Files
cpost-front/src/services/auth/index.ts
azizziy c01e852a59 init
2025-05-20 17:02:10 +05:00

32 lines
787 B
TypeScript

import { pageLinks } from '@/helpers/constants';
import { CookiesStore, LocalStore } from '@/services/local-store';
import { BROWSER_TOKEN_KEY } from '@/services/request';
class AuthService {
store: LocalStore;
constructor(config: { store: LocalStore }) {
this.store = config.store;
}
getToken() {
return this.store.get(BROWSER_TOKEN_KEY);
}
login(access_token: string) {
this.store.save(BROWSER_TOKEN_KEY, access_token);
}
clearCredentials() {
this.store.delete(BROWSER_TOKEN_KEY);
}
logout() {
this.store.delete(BROWSER_TOKEN_KEY);
this.store.resetStore();
window.location.replace(pageLinks.home);
}
}
export const auth_service = new AuthService({ store: new CookiesStore() });