-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from epigram5-9/merge/FE-54
FE-54๐๋ธ๋์น ์ต์
- Loading branch information
Showing
16 changed files
with
202 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import httpClient from '.'; | ||
|
||
const postGoogleOauth = async (code: string) => { | ||
const response = await httpClient.post('/auth/signIn/GOOGLE', { | ||
redirectUri: process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URI, | ||
token: code, | ||
}); | ||
return response.data; | ||
}; | ||
|
||
export default postGoogleOauth; |
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,12 @@ | ||
import httpClient from '.'; | ||
|
||
const postNaverOauth = async (code: string, state: string) => { | ||
const response = await httpClient.post('/auth/signIn/NAVER', { | ||
state, | ||
redirectUri: process.env.NEXT_PUBLIC_NAVER_REDIRECT_URI, | ||
token: code, | ||
}); | ||
return response.data; | ||
}; | ||
|
||
export default postNaverOauth; |
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,41 @@ | ||
import postGoogleOauth from '@/apis/postGoogleOauth'; | ||
import { toast } from '@/components/ui/use-toast'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { isAxiosError } from 'axios'; | ||
import { useRouter } from 'next/router'; | ||
|
||
const useGoogleLogin = () => { | ||
const router = useRouter(); | ||
|
||
return useMutation({ | ||
mutationFn: async (code: string) => { | ||
const result = await postGoogleOauth(code); | ||
localStorage.setItem('accessToken', result.accessToken); | ||
localStorage.setItem('refreshToken', result.refreshToken); | ||
return result; | ||
}, | ||
onSuccess: () => { | ||
router.push('/epigrams'); | ||
}, | ||
onError: (error) => { | ||
if (isAxiosError(error)) { | ||
const status = error.response?.status; | ||
|
||
if (!status) return; | ||
|
||
if (status === 400) { | ||
toast({ description: '์๋ชป๋ ์์ฒญ์ ๋๋ค. ์์ฒญ์ ํ์ธํด ์ฃผ์ธ์.', className: 'bg-state-error text-white font-semibold' }); | ||
router.push('/auth/SignIn'); | ||
return; | ||
} | ||
|
||
if (status >= 500) { | ||
toast({ description: '์๋ฒ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค. ์ ์ ํ ๋ค์ ์๋ํด ์ฃผ์ธ์.', className: 'bg-state-error text-white font-semibold' }); | ||
} | ||
} | ||
toast({ description: '์ ์ ์๋ ์๋ฌ๊ฐ ๋ฐ์ํ์ต๋๋ค.', className: 'bg-state-error text-white font-semibold' }); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useGoogleLogin; |
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,42 @@ | ||
import postNaverOauth from '@/apis/postNaverOauth'; | ||
import { toast } from '@/components/ui/use-toast'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { isAxiosError } from 'axios'; | ||
import { useRouter } from 'next/router'; | ||
|
||
const useNaverLogin = () => { | ||
const router = useRouter(); | ||
|
||
return useMutation({ | ||
mutationFn: async ({ code, state }: { code: string; state: string }) => { | ||
const result = await postNaverOauth(code, state); | ||
localStorage.setItem('accessToken', result.accessToken); | ||
localStorage.setItem('refreshToken', result.refreshToken); | ||
return result; | ||
}, | ||
onSuccess: () => { | ||
router.push('/epigrams'); | ||
}, | ||
onError: (error) => { | ||
if (isAxiosError(error)) { | ||
const status = error.response?.status; | ||
|
||
if (!status) return; | ||
|
||
if (status === 400) { | ||
toast({ description: '์๋ชป๋ ์์ฒญ์ ๋๋ค. ์์ฒญ์ ํ์ธํด ์ฃผ์ธ์.', className: 'bg-state-error text-white font-semibold' }); | ||
router.push('/auth/SignIn'); | ||
return; | ||
} | ||
|
||
if (status >= 500) { | ||
toast({ description: '์๋ฒ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค. ์ ์ ํ ๋ค์ ์๋ํด ์ฃผ์ธ์.', className: 'bg-state-error text-white font-semibold' }); | ||
} | ||
} | ||
|
||
toast({ description: '์ ์ ์๋ ์๋ฌ๊ฐ ๋ฐ์ํ์ต๋๋ค.', className: 'bg-state-error text-white font-semibold' }); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useNaverLogin; |
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
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,21 @@ | ||
import { useEffect } from 'react'; | ||
import { useSearchParams } from 'next/navigation'; | ||
import useGoogleLogin from '@/hooks/useGoogleLogin'; | ||
|
||
export default function Google() { | ||
const searchParams = useSearchParams(); | ||
const code = searchParams.get('code'); | ||
const { mutate: login } = useGoogleLogin(); | ||
|
||
useEffect(() => { | ||
if (code) { | ||
login(code); | ||
} else { | ||
/* eslint-disable no-console */ | ||
console.log(code); // code๊ฐ ์์ ๋ ์ฝ์์ ์ถ๋ ฅ | ||
} | ||
}, [code, login]); | ||
} | ||
|
||
// code๊ฐ ์๋ ๊ฒฝ์ฐ์ ์์ http://localhost:3000/auth/redirect/kakao | ||
// ํ ์คํธ๋ก ์๋ฌ ๋ฉ์์ง ๋์ฐ๊ณ , ๋ก๊ทธ์ธ ํ์ด์ง๋ก ๋ฆฌ๋ค์ด๋ ํธ |
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 useNaverLogin from '@/hooks/useNaverLogin'; | ||
import { useSearchParams } from 'next/navigation'; | ||
import { useEffect } from 'react'; | ||
|
||
export default function Naver() { | ||
const searchParams = useSearchParams(); | ||
const code = searchParams.get('code'); | ||
const state = searchParams.get('state'); | ||
const { mutate: login } = useNaverLogin(); | ||
|
||
useEffect(() => { | ||
if (code && state) { | ||
login({ code, state }); | ||
} else { | ||
/* eslint-disable no-console */ | ||
console.log(code, state); // code๊ฐ ์์ ๋ ์ฝ์์ ์ถ๋ ฅ | ||
} | ||
}, [code, state, login]); | ||
} |
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