koel/resources/assets/js/services/authService.ts

15 lines
377 B
TypeScript
Raw Normal View History

2022-05-14 18:49:45 +00:00
import { localStorageService } from '@/services'
2022-04-24 08:50:45 +00:00
2022-05-14 18:49:45 +00:00
const STORAGE_KEY = 'api-token'
2022-04-24 08:50:45 +00:00
2022-05-14 18:49:45 +00:00
export const authService = {
getToken: () => localStorageService.get<string | null>(STORAGE_KEY),
2022-04-24 08:50:45 +00:00
hasToken () {
return Boolean(this.getToken())
},
2022-05-14 18:49:45 +00:00
setToken: (token: string) => localStorageService.set(STORAGE_KEY, token),
destroy: () => localStorageService.remove(STORAGE_KEY)
2022-04-24 08:50:45 +00:00
}