stream/src/login.ts
2023-06-30 19:06:55 +02:00

32 lines
668 B
TypeScript

import { ExternalStore } from "@snort/shared";
export interface LoginSession {
pubkey: string;
follows: 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,
follows: [],
};
window.localStorage.setItem("session", JSON.stringify(this.#session));
this.notifyChange();
}
takeSnapshot() {
return this.#session ? { ...this.#session } : undefined;
}
}