Skip to content

Commit

Permalink
feat: add logout logics
Browse files Browse the repository at this point in the history
  • Loading branch information
eunbeann committed Aug 18, 2024
1 parent 3393cdd commit f7d2ee5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/apis/logout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { http } from './http';

export const getLogout = async () => {
return await http.get({
url: '/users/logout',
});
};
16 changes: 13 additions & 3 deletions src/app/(sidebar)/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use client';

import { postLogin } from '@/apis/login';
import { getLogout } from '@/apis/logout';
import { SSRSafeSuspense } from '@/lib';
import { Button } from '@/system/components';
import { useMutation } from '@tanstack/react-query';
import { setCookie } from 'cookies-next';
import { deleteCookie, setCookie } from 'cookies-next';
import { useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';
import { InputField } from '../my-recruit/components/NewRecruitDialogContent/InputField';
Expand All @@ -25,9 +26,9 @@ export default function Page() {
mutationFn: postLogin,
onSuccess: (data) => {
localStorage.setItem('accessToken', data.accessToken);
setCookie('refreshToken', data.refreshToken, { httpOnly: true, secure: true });
alert('로그인 성공');
setCookie('refreshToken', data.refreshToken, { secure: true });
router.replace('/');
alert('로그인 성공');
},
onError: () => {
alert('로그인 실패');
Expand All @@ -39,6 +40,15 @@ export default function Page() {
loginMutation.mutate({ loginId, password });
};

const logoutMutation = useMutation({
mutationFn: getLogout,
onSuccess: () => {
localStorage.removeItem('accessToken');
deleteCookie('refreshToken');
router.push('/');
},
});

return (
<SSRSafeSuspense
fallback={
Expand Down

0 comments on commit f7d2ee5

Please sign in to comment.