-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
82 changed files
with
1,875 additions
and
64 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { PostLoginRequest, PostLoginResponse } from '@/types/login'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { AxiosResponse } from 'axios'; | ||
import { setCookie } from 'cookies-next'; | ||
import { http } from './http'; | ||
|
||
export const postLogin = async ({ loginId, password }: PostLoginRequest): Promise<PostLoginResponse> => { | ||
const response: AxiosResponse<PostLoginResponse> = await http.post<PostLoginResponse>({ | ||
url: '/users/test/login', | ||
data: { | ||
loginId, | ||
password, | ||
}, | ||
}); | ||
|
||
return response.data; | ||
}; | ||
|
||
export const loginMutation = () => | ||
useMutation({ | ||
mutationFn: postLogin, | ||
onSuccess: (data) => { | ||
setCookie('accessToken', data.accessToken); | ||
setCookie('refreshToken', data.refreshToken); | ||
window.location.href = '/'; | ||
alert('로그인 성공'); | ||
}, | ||
onError: () => { | ||
alert('로그인 실패'); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { deleteCookie } from 'cookies-next'; | ||
import { http } from './http'; | ||
|
||
export const getLogout = async () => { | ||
return await http.get({ | ||
url: '/users/logout', | ||
}); | ||
}; | ||
|
||
export const logoutMutation = () => | ||
useMutation({ | ||
mutationFn: getLogout, | ||
onSuccess: () => { | ||
deleteCookie('accessToken'); | ||
deleteCookie('refreshToken'); | ||
window.location.href = '/'; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { PostLoginResponse, PostRefreshRequest } from '@/types/login'; | ||
import { http } from './http'; | ||
|
||
export const postRefresh = ({ refreshToken }: PostRefreshRequest) => { | ||
return http.post<PostLoginResponse>({ | ||
url: '/users/refreshToken', | ||
data: { | ||
refreshToken, | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
'use client'; | ||
|
||
import { loginMutation } from '@/apis/login'; | ||
import { logoutMutation } from '@/apis/logout'; | ||
import { SSRSafeSuspense } from '@/lib'; | ||
import { Button } from '@/system/components'; | ||
import { getCookie } from 'cookies-next'; | ||
import { useRouter } from 'next/navigation'; | ||
import { useEffect, useState } from 'react'; | ||
import { InputField } from '../my-recruit/components/NewRecruitDialogContent/InputField'; | ||
|
||
export default function Page() { | ||
const router = useRouter(); | ||
|
||
const [loginId, setLoginId] = useState<string>(''); | ||
const [password, setPassword] = useState<string>(''); | ||
const [isLogin, setIsLogin] = useState<boolean>(false); | ||
|
||
const { mutate: loginMutate } = loginMutation(); | ||
const { mutate: logoutMutate } = logoutMutation(); | ||
|
||
useEffect(() => { | ||
const token = getCookie('accessToken'); | ||
setIsLogin(token != null); | ||
}, []); | ||
|
||
const handleLogin = async (event: React.FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
loginMutate({ loginId, password }); | ||
}; | ||
|
||
return ( | ||
<SSRSafeSuspense | ||
fallback={ | ||
<div className="w-full h-full flex justify-center items-center"> | ||
<div>로딩 중...</div> | ||
</div> | ||
}> | ||
<div className="w-full h-full flex justify-center items-center"> | ||
{isLogin ? ( | ||
<div className="flex flex-col gap-4"> | ||
<div>이미 로그인 되어있습니다.</div> | ||
<Button | ||
className="bg-neutral-95 flex items-center gap-[4px] py-[8px] px-[16px] rounded-[6px]" | ||
onClick={() => { | ||
router.replace('/'); | ||
}}> | ||
<span className="w-full text-label1 text-white font-semibold">홈으로</span> | ||
</Button> | ||
<Button | ||
className="bg-neutral-95 flex items-center gap-[4px] py-[8px] px-[16px] rounded-[6px]" | ||
onClick={() => { | ||
logoutMutate(); | ||
}}> | ||
<span className="w-full text-label1 text-white font-semibold">로그아웃</span> | ||
</Button> | ||
</div> | ||
) : ( | ||
<form onSubmit={handleLogin}> | ||
<div className="flex flex-col justify-center gap-10 mb-15"> | ||
<InputField value={loginId} onChange={(e) => setLoginId(e.target.value)} placeholder="이메일" /> | ||
<InputField | ||
type="password" | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
placeholder="비밀번호" | ||
className="mb-4" | ||
/> | ||
</div> | ||
<div className="flex gap-2 flex-col"> | ||
<Button className="bg-neutral-95 flex items-center gap-[4px] py-[8px] px-[16px] rounded-[6px]"> | ||
<span className="w-full text-label1 text-white font-semibold">로그인</span> | ||
</Button> | ||
</div> | ||
</form> | ||
)} | ||
</div> | ||
</SSRSafeSuspense> | ||
); | ||
} |
2 changes: 1 addition & 1 deletion
2
src/app/(sidebar)/my-recruit/components/NewRecruitDialogContent/InputField.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.