init
This commit is contained in:
31
src/services/auth/index.ts
Normal file
31
src/services/auth/index.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
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() });
|
||||
Reference in New Issue
Block a user