Create file constant
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import axios from "axios";
|
||||
import { API_BASE_URL } from "@/config/const";
|
||||
|
||||
export type RefreshTokenRequestModel = {
|
||||
token: string;
|
||||
@@ -6,7 +7,7 @@ export type RefreshTokenRequestModel = {
|
||||
|
||||
export const refreshToken = async (model: RefreshTokenRequestModel) => {
|
||||
const res = await axios.post(
|
||||
`${process.env.NEXT_PUBLIC_API_BASE_URL}/public/auth/refresh`,
|
||||
`${API_BASE_URL}/public/auth/refresh`,
|
||||
{ refreshToken: model.token },
|
||||
{
|
||||
headers: { "Content-Type": "application/json" },
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
removeRefreshToken,
|
||||
} from "./func";
|
||||
import { refreshToken } from "./auth/refresh-token";
|
||||
import { API_BASE_URL } from "@/config/const";
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
@@ -16,7 +17,7 @@ declare global {
|
||||
}
|
||||
|
||||
const axiosInstance = axios.create({
|
||||
baseURL: process.env.NEXT_PUBLIC_API_BASE_URL,
|
||||
baseURL: API_BASE_URL,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
|
||||
|
||||
+8
-19
@@ -1,42 +1,31 @@
|
||||
import { REFRESH_TOKEN_NAME, TOKEN_NAME } from "@/config/const";
|
||||
|
||||
export const getToken = async (): Promise<string | null> => {
|
||||
if (typeof window === "undefined") return null;
|
||||
return localStorage.getItem(
|
||||
process.env.NEXT_PUBLIC_TOKEN_NAME as string
|
||||
);
|
||||
return localStorage.getItem(TOKEN_NAME);
|
||||
};
|
||||
|
||||
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
|
||||
);
|
||||
return localStorage.getItem(REFRESH_TOKEN_NAME);
|
||||
};
|
||||
|
||||
export const setToken = async (token: string): Promise<void> => {
|
||||
if (typeof window === "undefined") return;
|
||||
localStorage.setItem(
|
||||
process.env.NEXT_PUBLIC_TOKEN_NAME as string,
|
||||
token
|
||||
);
|
||||
localStorage.setItem(TOKEN_NAME, 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
|
||||
);
|
||||
localStorage.setItem(REFRESH_TOKEN_NAME, token);
|
||||
};
|
||||
|
||||
export const removeToken = async (): Promise<void> => {
|
||||
if (typeof window === "undefined") return;
|
||||
localStorage.removeItem(process.env.NEXT_PUBLIC_TOKEN_NAME as string);
|
||||
localStorage.removeItem(TOKEN_NAME);
|
||||
};
|
||||
|
||||
export const removeRefreshToken = async (): Promise<void> => {
|
||||
if (typeof window === "undefined") return;
|
||||
localStorage.removeItem(
|
||||
process.env.NEXT_PUBLIC_REFRESH_TOKEN_NAME as string
|
||||
);
|
||||
localStorage.removeItem(REFRESH_TOKEN_NAME);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user