43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
export const getToken = async (): Promise<string | null> => {
|
|
if (typeof window === "undefined") return null;
|
|
return localStorage.getItem(
|
|
process.env.NEXT_PUBLIC_TOKEN_NAME as string
|
|
);
|
|
};
|
|
|
|
export const getRefreshToken = async (): Promise<string | null> => {
|
|
if (typeof window === "undefined") return null;
|
|
return localStorage.getItem(
|
|
process.env.NEXT_PUBLIC_REFRESH_TOKEN_NAME as string
|
|
);
|
|
};
|
|
|
|
export const setToken = async (token: string): Promise<void> => {
|
|
if (typeof window === "undefined") return;
|
|
localStorage.setItem(
|
|
process.env.NEXT_PUBLIC_TOKEN_NAME as string,
|
|
token
|
|
);
|
|
};
|
|
|
|
export const setRefreshToken = async (token: string): Promise<void> => {
|
|
if (typeof window === "undefined") return;
|
|
localStorage.setItem(
|
|
process.env.NEXT_PUBLIC_REFRESH_TOKEN_NAME as string,
|
|
token
|
|
);
|
|
};
|
|
|
|
export const removeToken = async (): Promise<void> => {
|
|
if (typeof window === "undefined") return;
|
|
localStorage.removeItem(process.env.NEXT_PUBLIC_TOKEN_NAME as string);
|
|
};
|
|
|
|
export const removeRefreshToken = async (): Promise<void> => {
|
|
if (typeof window === "undefined") return;
|
|
localStorage.removeItem(
|
|
process.env.NEXT_PUBLIC_REFRESH_TOKEN_NAME as string
|
|
);
|
|
};
|
|
|