This commit is contained in:
2023-06-21 15:28:17 +01:00
parent 9c88f2e28f
commit 6f0dc2e430
11 changed files with 154 additions and 47 deletions

29
src/login.ts Normal file
View File

@ -0,0 +1,29 @@
import { ExternalStore } from "@snort/shared";
export interface LoginSession {
pubkey: string
}
export class LoginStore extends ExternalStore<LoginSession | undefined> {
#session?: LoginSession;
constructor() {
super();
const json = window.localStorage.getItem("session");
if (json) {
this.#session = JSON.parse(json);
}
}
loginWithPubkey(pk: string) {
this.#session = {
pubkey: pk
};
window.localStorage.setItem("session", JSON.stringify(this.#session));
this.notifyChange();
}
takeSnapshot() {
return this.#session ? { ...this.#session } : undefined;
}
}