-
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 #112 from TripInfoWeb/dev_auth
google oauth 추가 및 백엔드 연결 확인
- Loading branch information
Showing
7 changed files
with
71 additions
and
5 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,6 @@ | ||
import { NextResponse } from "next/server"; | ||
|
||
export function GET() { | ||
const googleAuthUrl = `https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=${process.env.GOOGLE_CLIENT_ID}&redirect_uri=${process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URL}&scope=email profile&prompt=select_account`; | ||
return NextResponse.redirect(googleAuthUrl); | ||
} |
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,6 +1,6 @@ | ||
import { NextResponse } from "next/server"; | ||
|
||
export function GET() { | ||
const kakaoAuthUrl = `https://kauth.kakao.com/oauth/authorize?response_type=code&client_id=${process.env.NODE_ENV === "development" ? process.env.NEXT_PUBLIC_KAKAO_REST_API_KEY : process.env.KAKAO_REST_API_KEY}&redirect_uri=${process.env.NEXT_PUBLIC_KAKAO_REDIRECT_URI}`; | ||
const kakaoAuthUrl = `https://kauth.kakao.com/oauth/authorize?response_type=code&client_id=${process.env.KAKAO_REST_API_KEY}&redirect_uri=${process.env.NEXT_PUBLIC_KAKAO_REDIRECT_URL}`; | ||
return NextResponse.redirect(kakaoAuthUrl); | ||
} |
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,9 @@ | ||
import AuthGoogleContainer from "@/containers/auth/AuthGoogleContainer"; | ||
|
||
const Page = () => { | ||
|
||
return ( | ||
<AuthGoogleContainer/> | ||
); | ||
}; | ||
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
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,51 @@ | ||
"use client"; | ||
|
||
import AuthLoading from "@/components/auth/AuthLoading"; | ||
import useAuthStore from "@/store/authStore"; | ||
import UrlQueryStringToObject from "@/utils/UrlQueryStringToObject"; | ||
import { useRouter } from "next/navigation"; | ||
import { useEffect } from "react"; | ||
|
||
const AuthGoogleContainer = () => { | ||
const router = useRouter(); | ||
const authStore = useAuthStore(); | ||
|
||
useEffect(() => { | ||
const _queryStringObject = UrlQueryStringToObject<{ | ||
[key: string]: string; | ||
}>(window.location.href); | ||
const googleLogin = async () => { | ||
try { | ||
const response = await fetch( | ||
`${process.env.NEXT_PUBLIC_BACKEND_URL}/api/auth/oauth2/login?type=google&redirectUrl=${process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URL}&code=${_queryStringObject?.code}`, | ||
{ | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json;charset=utf-8", | ||
"Access-Control-Allow-Origin": "*", | ||
}, | ||
credentials: "include", | ||
}, | ||
); | ||
|
||
if (!response.ok) { | ||
throw new Error("Network response was not ok"); | ||
} | ||
|
||
// const res = await response.json(); | ||
// res.accessToken 받아서 사용자 정보 받아오고 홈으로 이동 | ||
authStore.setUser({ nickname: "성공" }); | ||
router.push("/"); | ||
} catch (error) { | ||
console.error("로그인 실패", error); | ||
router.push("/auth/signin"); | ||
} | ||
}; | ||
|
||
googleLogin(); | ||
}, []); | ||
|
||
return <AuthLoading />; | ||
}; | ||
|
||
export default AuthGoogleContainer; |
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