Private
Public Access
46 lines
983 B
TypeScript
46 lines
983 B
TypeScript
export interface AuthTokens {
|
|
access_token: string;
|
|
refresh_token: string;
|
|
expires_in: number;
|
|
token_type: string;
|
|
}
|
|
|
|
export function setToken(token: string): void {
|
|
if (typeof window !== 'undefined') {
|
|
localStorage.setItem('token', token);
|
|
}
|
|
}
|
|
|
|
export function removeToken(): void {
|
|
if (typeof window !== 'undefined') {
|
|
localStorage.removeItem('token');
|
|
}
|
|
}
|
|
|
|
export function getToken(): string {
|
|
if (typeof window !== 'undefined') {
|
|
return localStorage.getItem('token') || '';
|
|
}
|
|
return '';
|
|
}
|
|
|
|
export function setAuthTokens(auth: AuthTokens): void {
|
|
if (typeof window !== 'undefined') {
|
|
localStorage.setItem('auth', JSON.stringify(auth));
|
|
}
|
|
}
|
|
|
|
export function getAuthTokens(): AuthTokens | null {
|
|
if (typeof window !== 'undefined') {
|
|
const auth = localStorage.getItem('auth');
|
|
return auth ? JSON.parse(auth) : null;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function removeAuthTokens(): void {
|
|
if (typeof window !== 'undefined') {
|
|
localStorage.removeItem('auth');
|
|
}
|
|
}
|