access_token 이 없지만 refresh_token 이 있으면 access_token 갱신처리

이미 로그인 한 상태에서 로그인 페이지로 이동하면 첫페이지로 리다이렉트
This commit is contained in:
2026-01-02 12:51:07 +09:00
parent 767435cad4
commit 3ebd34d2de
6 changed files with 76 additions and 26 deletions

View File

@@ -9,6 +9,14 @@ export const getAccessTokenFromCookie = (): string | null => {
return null;
};
export const getRefreshTokenFromCookie = (): string | null => {
const name = 'refresh_token';
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop()?.split(';').shift() || null;
return null;
};
export interface LoginCredentials {
memberId: string;
password: string;
@@ -77,3 +85,14 @@ export const getUserFromToken = (token: string): DecodedToken | null => {
return null;
}
};
// Access Token 갱신 API
export const renewAccessToken = async (refreshToken: string): Promise<AuthResponse> => {
// Refresh Token을 Header에 담아 전송 (Authorization: Bearer <token>)
const response = await axios.post<AuthResponse>('/auth/renewAccessToken', null, {
headers: {
'Authorization': `Bearer ${refreshToken}`
}
});
return response.data;
};