Skip to content

Commit

Permalink
feat: 로그아웃 API 추가 (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
selfishAltruism committed Mar 6, 2024
1 parent 4e8a270 commit aa99ad1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/@types/user.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ declare namespace User {
email: string;
}

export interface SignOutRequestDto {
accessToken: string;
refreshToken: string;
}

// ==

export interface FindPostsResponse {
Expand Down
1 change: 1 addition & 0 deletions src/configs/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const API = axios.create({
export const setAccess = (token: string): unknown =>
(API.defaults.headers['Authorization'] = token);
export const resetAccess = (): unknown => delete API.defaults.headers['Authorization'];
export const getAccess = (): string => `${API.defaults.headers['Authorization']}`;

//Refresh
const storageRefreshKey = 'CAUCSE_JWT_REFRESH';
Expand Down
3 changes: 2 additions & 1 deletion src/stores/AuthStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { makeAutoObservable } from 'mobx';

import { AuthRepoImpl as Repo } from './repositories/AuthRepo';

import { getRefresh, removeRefresh, resetAccess } from '@/configs/axios';
import { getRefresh, removeRefresh, resetAccess, getAccess } from '@/configs/axios';

export class AuthStore {
rootStore: Store.Root;
Expand Down Expand Up @@ -35,6 +35,7 @@ export class AuthStore {
}

signOut(): void {
Repo.signOut({ accessToken: getAccess(), refreshToken: getRefresh() ?? '' });
resetAccess();
removeRefresh();
}
Expand Down
4 changes: 4 additions & 0 deletions src/stores/repositories/AuthRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class AuthRepo {
findPassword = async (body: User.FindPasswordReqestDto) => {
return API.put(`${this.URI}/password/find`, body);
};

signOut = async (body: User.SignOutRequestDto) => {
return API.put(`${this.URI}/sign-out`, body);
};
}

export const AuthRepoImpl = new AuthRepo();

0 comments on commit aa99ad1

Please sign in to comment.