-
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
1 parent
3d7ee32
commit ebc0b33
Showing
15 changed files
with
337 additions
and
4 deletions.
There are no files selected for viewing
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,11 @@ | ||
import { http, refreshTokenHeader } from '@/modules/services'; | ||
|
||
export const requestLogin = async (authCode: string) => { | ||
const { data } = await http.post('/auth/oauth/bsm', {}, { headers: { authCode } }); | ||
return data; | ||
}; | ||
|
||
export const requestLogout = async () => { | ||
const { data } = await http.delete('/auth/bsm/logout', refreshTokenHeader()); | ||
return data; | ||
}; |
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,26 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { requestLogin, requestLogout } from './axios'; | ||
import { Storage } from '@/modules/services'; | ||
import { Bumawiki } from '@/modules/constants'; | ||
|
||
export const useLoginMutation = () => { | ||
return useMutation({ | ||
mutationFn: requestLogin, | ||
onSuccess: ({ accessToken, refreshToken }) => { | ||
Storage.setItem(Bumawiki.token.access, accessToken); | ||
Storage.setItem(Bumawiki.token.refresh, refreshToken); | ||
window.history.go(-2); | ||
}, | ||
}); | ||
}; | ||
|
||
export const useLogoutMutation = () => { | ||
return useMutation({ | ||
mutationFn: requestLogout, | ||
onSuccess: window.location.reload, | ||
onSettled: () => { | ||
Storage.delItem(Bumawiki.token.access); | ||
Storage.delItem(Bumawiki.token.refresh); | ||
}, | ||
}); | ||
}; |
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 @@ | ||
export {}; |
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 @@ | ||
export { AuthenticationPage } from './ui/AuthenticationPage'; |
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,24 @@ | ||
import { useLoginMutation } from '../../_entities/api/mutation'; | ||
import { useMount } from '@/hooks/useMount'; | ||
import { useSearchParams } from 'next/navigation'; | ||
import React, { useEffect } from 'react'; | ||
|
||
export const withAuthentication = <P extends object>(Component: React.ComponentType<P>) => { | ||
const WrappedComponent: React.FC<P> = (props) => { | ||
const { mutate: login } = useLoginMutation(); | ||
const isMounted = useMount(); | ||
const authCode = useSearchParams().get('code') || ''; | ||
|
||
useEffect(() => { | ||
if (isMounted) login(authCode); | ||
}, [isMounted, authCode, login]); | ||
|
||
return <Component {...props} />; | ||
}; | ||
|
||
WrappedComponent.displayName = `withAuthentication(${ | ||
Component.displayName || Component.name || 'Component' | ||
})`; | ||
|
||
return WrappedComponent; | ||
}; |
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,13 @@ | ||
'use client'; | ||
|
||
import { MoonLoader } from 'react-spinners'; | ||
import { withAuthentication } from '../lib/withAuthentication'; | ||
|
||
export const AuthenticationPage = withAuthentication(() => { | ||
return ( | ||
<main className="flex flex-col items-center justify-center w-full h-screen gap-4"> | ||
<MoonLoader size={40} color="#274168" /> | ||
<span className="text-label-medium font-semibold">로그인 중...</span> | ||
</main> | ||
); | ||
}); |
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,18 @@ | ||
import { Suspense } from 'react'; | ||
import { AuthenticationPage } from './_features'; | ||
import { Metadata, NextPage } from 'next'; | ||
|
||
export const metadata: Metadata = { | ||
title: '부마위키 | 로그인', | ||
description: '로그인 후 부마위키 문서에 직접 기여해보세요.', | ||
}; | ||
|
||
const Page: NextPage = () => { | ||
return ( | ||
<Suspense> | ||
<AuthenticationPage /> | ||
</Suspense> | ||
); | ||
}; | ||
|
||
export default Page; |
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.