feat: client request 인증 로직 추가 #3

Merged
chanii8 merged 1 commits from iipbs_cs into main 2025-03-11 16:34:30 +09:00
8 changed files with 45 additions and 13 deletions
+4 -1
View File
@@ -5,4 +5,7 @@
node_modules
# misc
.DS_Store
.DS_Store
# env
.env*
@@ -1,18 +1,11 @@
import { client } from "@/shared/api";
import { getToken } from "@/shared/lib/cookie";
import { AUTH_USER_ID, CLAIM_NAME, ENDPOINT } from "@/shared/config";
import type { IUser, IUserInfo, UserService } from "../model/user";
import { ENDPOINT } from "@/shared/config";
import type { IUser, IUserInfo, UserService } from "../model/user-interface";
export class UsersApiService implements UserService {
public async userInfo(payload: IUserInfo): Promise<IUser> {
const response = await client.get<IUser>(
`${ENDPOINT.USER_SERVICE.USERS}/${payload.userUniqId}`,
{
headers: {
[CLAIM_NAME]: `${getToken(CLAIM_NAME)}`,
[AUTH_USER_ID]: `${getToken(AUTH_USER_ID)}`,
},
},
);
return response.data;
+16
View File
@@ -1,5 +1,7 @@
import axios from "axios";
import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
import Cookies from "js-cookie";
import { AUTH_USER_ID, CLAIM_NAME } from "./env";
interface ClientConfig {
baseURL: string;
@@ -19,6 +21,20 @@ class Client {
},
withCredentials: true,
});
this.axiosInstance.interceptors.request.use((config) => {
const token = Cookies.get(CLAIM_NAME);
const userId = Cookies.get(AUTH_USER_ID);
if (!token || !userId) {
throw new Error("Missing required authentication tokens");
}
config.headers[CLAIM_NAME] = token;
config.headers[AUTH_USER_ID] = userId;
return config;
});
}
public static getInstance(config: ClientConfig): Client {
+4
View File
@@ -0,0 +1,4 @@
export const CLAIM_NAME = process.env.CLAIM_NAME || "Authorization";
export const ACCESS_TOKEN = process.env.ACCESS_TOKEN || "access-token";
export const REFRESH_TOKEN = process.env.REFRESH_TOKEN || "refresh-token";
export const AUTH_USER_ID = process.env.AUTH_USER_ID || "token-id";
+3 -1
View File
@@ -8,7 +8,9 @@
".": "./index.ts"
},
"dependencies": {
"axios": "^1.8.1"
"@types/js-cookie": "^3.0.6",
"axios": "^1.8.1",
"js-cookie": "^3.0.5"
},
"devDependencies": {
"@types/node": "^20.11.19",
+4 -1
View File
@@ -1,6 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": "."
"baseUrl": ".",
"module": "ESNext"
},
"include": ["."],
"exclude": ["node_modules", "dist"]
+12 -1
View File
@@ -166,6 +166,9 @@ importers:
'@tanstack/react-table':
specifier: ^8.21.2
version: 8.21.2(react-dom@18.3.1)(react@18.3.1)
'@types/js-cookie':
specifier: ^3.0.6
version: 3.0.6
axios:
specifier: ^1.8.1
version: 1.8.1
@@ -181,6 +184,9 @@ importers:
date-fns:
specifier: ^3.6.0
version: 3.6.0
js-cookie:
specifier: ^3.0.5
version: 3.0.5
lucide-react:
specifier: ^0.474.0
version: 0.474.0(react@18.3.1)
@@ -296,9 +302,15 @@ importers:
packages/common/network:
dependencies:
'@types/js-cookie':
specifier: ^3.0.6
version: 3.0.6
axios:
specifier: ^1.8.1
version: 1.8.1
js-cookie:
specifier: ^3.0.5
version: 3.0.5
devDependencies:
'@types/node':
specifier: ^20.11.19
@@ -2952,7 +2964,6 @@ packages:
/@types/js-cookie@3.0.6:
resolution: {integrity: sha512-wkw9yd1kEXOPnvEeEV1Go1MmxtBJL0RR79aOTAApecWFVu7w0NNXNqhcWgvw2YgZDYadliXkl14pa3WXw5jlCQ==}
dev: true
/@types/json-schema@7.0.15:
resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==}