-
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.
* feat : 로그인 기능 #75 * fix : fetcher 내부에서 에러 발생 시에도 response return #75 * fix : redirect 대신 router 사용 #75 * feat : git action에 .env 생성 스크립트 추가 #75 * chore : 테스트용 스크립트 제거 #75
- Loading branch information
1 parent
1f65f22
commit 5249ed1
Showing
7 changed files
with
110 additions
and
22 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
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,14 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
import { fetcher } from '@/app/api/fetcher'; | ||
|
||
const loginFetcher = fetcher(); | ||
|
||
const postGoogleLoginFetch = () => { | ||
return async (code: string | null) => | ||
loginFetcher('/login/google', { | ||
method: 'POST', | ||
body: { code }, | ||
}); | ||
}; | ||
|
||
export { postGoogleLoginFetch }; |
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,32 @@ | ||
'use client'; | ||
|
||
import { useSetAtom } from 'jotai'; | ||
import { useRouter } from 'next/navigation'; | ||
|
||
import { postGoogleLoginFetch } from '@/app/api/login'; | ||
import { userAtom } from '@/atom'; | ||
|
||
const Page = ({ searchParams }: { searchParams: { code: string } }) => { | ||
const { code } = searchParams; | ||
const router = useRouter(); | ||
|
||
const setUser = useSetAtom(userAtom); | ||
|
||
const login = postGoogleLoginFetch(); | ||
login(code).then((res) => { | ||
if (res?.ok) { | ||
setUser({ | ||
memberId: res.body?.memberId, | ||
token: res.body?.token, | ||
isLogin: true, | ||
}); | ||
} else { | ||
alert(res.body.message); | ||
} | ||
router.replace('/'); | ||
}); | ||
|
||
return <div />; | ||
}; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
'use client'; | ||
|
||
import { ChakraProvider } from '@chakra-ui/react'; | ||
import { Provider, createStore } from 'jotai'; | ||
|
||
import theme from '@/theme'; | ||
|
||
const store = createStore(); | ||
|
||
const Providers = ({ children }: { children: React.ReactNode }) => { | ||
return <ChakraProvider theme={theme}>{children}</ChakraProvider>; | ||
return ( | ||
<ChakraProvider theme={theme}> | ||
<Provider store={store}>{children}</Provider> | ||
</ChakraProvider> | ||
); | ||
}; | ||
|
||
export default Providers; |
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,8 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
import { atomWithStorage } from 'jotai/utils'; | ||
|
||
export const userAtom = atomWithStorage('user', { | ||
memberId: 0, | ||
token: '', | ||
isLogin: false, | ||
}); |
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