Persist auth token

This commit is contained in:
Caleb Owens 2024-10-11 12:04:11 +02:00
parent ba2d95a338
commit 253fc4ed62

View File

@ -1,19 +1,18 @@
import { get, writable } from 'svelte/store'; import { persisted } from '@gitbutler/shared/persisted';
import { type Readable } from 'svelte/store';
export class AuthService { export class AuthService {
token = writable<string | undefined>(undefined); #token = persisted<string | undefined>(undefined, 'AuthService--token');
constructor() {} get token(): Readable<string | undefined> {
return this.#token;
getToken() {
return get(this.token);
} }
setToken(data: string) { setToken(data: string) {
this.token.set(data); this.#token.set(data);
} }
clearToken() { clearToken() {
this.token.set(''); this.#token.set(undefined);
} }
} }