|
1 | 1 | import axios from "axios"; |
2 | 2 | import { env } from "@/config/env"; |
3 | | - |
4 | | -const STORAGE_PREFIX = "fullstack_"; |
5 | | - |
6 | | -const STORAGE_KEYS = { |
7 | | - ACCESS_TOKEN: `${STORAGE_PREFIX}access_token`, |
8 | | - REFRESH_TOKEN: `${STORAGE_PREFIX}refresh_token`, |
9 | | -}; |
10 | | - |
11 | | -function getAccessToken() { |
12 | | - if (typeof window === "undefined") return null; |
13 | | - return localStorage.getItem(STORAGE_KEYS.ACCESS_TOKEN); |
14 | | -} |
15 | | - |
16 | | -function getRefreshToken() { |
17 | | - if (typeof window === "undefined") return null; |
18 | | - return localStorage.getItem(STORAGE_KEYS.REFRESH_TOKEN); |
19 | | -} |
20 | | - |
21 | | -function setAccessToken(token: string) { |
22 | | - if (typeof window !== "undefined") { |
23 | | - localStorage.setItem(STORAGE_KEYS.ACCESS_TOKEN, token); |
24 | | - } |
25 | | -} |
26 | | - |
27 | | -function setRefreshToken(token: string) { |
28 | | - if (typeof window !== "undefined") { |
29 | | - localStorage.setItem(STORAGE_KEYS.REFRESH_TOKEN, token); |
30 | | - } |
31 | | -} |
32 | | - |
33 | | -function clearTokens() { |
34 | | - if (typeof window !== "undefined") { |
35 | | - localStorage.removeItem(STORAGE_KEYS.ACCESS_TOKEN); |
36 | | - localStorage.removeItem(STORAGE_KEYS.REFRESH_TOKEN); |
37 | | - } |
38 | | -} |
| 3 | +import { clearTokens, getAccessToken, getRefreshToken, setAccessToken } from "@/lib/auth/token"; |
39 | 4 |
|
40 | 5 | export const apiClient = axios.create({ |
41 | 6 | baseURL: env.NEXT_PUBLIC_API_URL, |
@@ -124,5 +89,3 @@ apiClient.interceptors.response.use( |
124 | 89 | return Promise.reject(error); |
125 | 90 | } |
126 | 91 | ); |
127 | | - |
128 | | -export { getAccessToken, getRefreshToken, setAccessToken, setRefreshToken, clearTokens }; |
0 commit comments