Skip to content

Commit

Permalink
Merge pull request #338 from KakaoFunding/feat/312
Browse files Browse the repository at this point in the history
Feat/312 소셜 로그아웃 요청 로직 추가
  • Loading branch information
ohgus authored Jun 3, 2024
2 parents 3b8d6c2 + 435c13b commit 426d875
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
8 changes: 5 additions & 3 deletions src/layouts/App/Header/LogoutModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
clearLocalStorageItem,
getLocalStorageItem,
} from 'services/api/v1/localStorage';
import { logout } from 'services/api/v1/oauth';
import { logout, socialLogout } from 'services/api/v1/oauth';
import {
clearSessionStorageItem,
getSessionStorageItem,
Expand All @@ -28,11 +28,13 @@ const LogoutModal = ({ modalState, userState }: LogoutModalProps) => {
const clearSelectedFiends = useSelectedFriendsStore(
(state) => state.clearSelectedFriends,
);
const accessToken = getSessionStorageItem('accessToken');
const refreshToken = getLocalStorageItem('refreshToken');
const socialAccessToken = getSessionStorageItem('socialToken');
const { providerId } = useUserStore();

const handleLogout = async () => {
await logout({ accessToken, refreshToken });
await logout({ refreshToken });
await socialLogout({ providerId, socialAccessToken });

clearUser();
clearSelectedFiends();
Expand Down
34 changes: 22 additions & 12 deletions src/services/api/v1/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ type LoginResponseProps = {
};

type LogoutRequestProps = {
accessToken: string | null;
refreshToken: string | null;
refreshToken: string;
};

type SocialLogoutRequestProps = {
socialAccessToken: string;
providerId: string;
};

// 로그인: 토큰 발급
Expand Down Expand Up @@ -71,16 +75,22 @@ export const login = async ({

// 로그아웃 요청
export const logout = async ({
accessToken,
refreshToken,
}: LogoutRequestProps): Promise<AxiosResponse<LogoutRequestProps>> => {
const headers = {
Authorization: `Bearer ${accessToken}`,
};
const response = await apiV1.post(
'/oauth/logout',
{ refreshToken },
{ headers },
);
}: LogoutRequestProps): Promise<AxiosResponse> => {
const response = await apiV1.post('/oauth/logout', { refreshToken });
return response;
};

// 소셜 로그아웃
export const socialLogout = async ({
providerId,
socialAccessToken,
}: SocialLogoutRequestProps): Promise<AxiosResponse> => {
const response = await apiV1.post('/oauth/social/logout', {
provider: 'KAKAO',
providerId,
socialAccessToken,
});

return response;
};

0 comments on commit 426d875

Please sign in to comment.