-
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 branch 'main' of https://github.com/epigram5-9/epigram into mer…
…ge/FE-27--merge
- 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