diff --git a/src/app/auth/facebook/login/route.ts b/src/app/auth/facebook/login/route.ts index efa00b7..2847028 100644 --- a/src/app/auth/facebook/login/route.ts +++ b/src/app/auth/facebook/login/route.ts @@ -1,7 +1,25 @@ +import { authLogin, getKakaoToken } from '@/services' +import { cookies } from 'next/headers' import { NextResponse } from 'next/server' export async function GET(request: Request) { const requestUrl = new URL(request.url) - console.log(`requestUrl is : ${requestUrl}`) - return NextResponse.redirect(`${requestUrl.origin}`) + const code = requestUrl.searchParams.get('code') + + console.log('haha : ' + requestUrl) + + // if (code) { + // return getKakaoToken(code).then(async (data) => { + // return await authLogin('kakao', data.access_token) + // .then((response) => + // NextResponse.redirect(`${process.env.NEXT_PUBLIC_ORIGIN_URL}`), + // ) + // .catch((error) => { + // cookies().set('Access_Token', data.access_token) + // return NextResponse.redirect(`${requestUrl.origin}/signup?kind=kakao`) + // }) + // }) + // } + + return NextResponse.redirect(requestUrl.origin) } diff --git a/src/app/auth/login/route.ts b/src/app/auth/login/route.ts index e8a2deb..f14ca05 100644 --- a/src/app/auth/login/route.ts +++ b/src/app/auth/login/route.ts @@ -1,9 +1,18 @@ +import { authLogin } from '@/services' +import { AuthKindType } from '@/types' +import { cookies } from 'next/headers' import { NextResponse } from 'next/server' export async function GET(request: Request) { const requestUrl = new URL(request.url) const kind = requestUrl.searchParams.get('kind') - console.log(`login with ${kind}`) + const signed = requestUrl.searchParams.get('signed') + const access_token = cookies().get('Access_Token')?.value + + if (signed) { + await authLogin(kind as AuthKindType, access_token || '') + return NextResponse.redirect(requestUrl.origin) + } if (kind === 'google') { return NextResponse.redirect( @@ -12,7 +21,7 @@ export async function GET(request: Request) { } if (kind === 'facebook') { return NextResponse.redirect( - `https://accounts.google.com/o/oauth2/v2/auth?client_id=${process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID}&response_type=token&redirect_uri=${process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URI}&scope=https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile`, + `https://www.facebook.com/v20.0/dialog/oauth?client_id=${process.env.NEXT_PUBLIC_FACEBOOK_CLIENT_ID}&redirect_uri=${process.env.NEXT_PUBLIC_FACEBOOK_REDIRECT_URI}&response_type=token`, ) } if (kind === 'kakao') { diff --git a/src/components/modal/SignupModal.tsx b/src/components/modal/SignupModal.tsx index 833c7ba..aa5a2ef 100644 --- a/src/components/modal/SignupModal.tsx +++ b/src/components/modal/SignupModal.tsx @@ -35,7 +35,7 @@ export const SignupModal = ({ kind }: { kind: string }) => { } const access_token = getCookie('Access_Token') await authSignup(kind as AuthKindType, access_token || '', signupJson).then( - () => loginRedirect(kind as AuthKindType), + () => loginRedirect(kind as AuthKindType, true), ) } diff --git a/src/services/authSignup.ts b/src/services/authSignup.ts index d0f47b9..6ce2c5b 100644 --- a/src/services/authSignup.ts +++ b/src/services/authSignup.ts @@ -14,6 +14,9 @@ export const authSignup = async ( }, data: data, }) - .then((response) => response.data) + .then((response) => { + console.log(response.headers) + return response.data + }) .catch((error) => console.log(error)) } diff --git a/src/utils/loginRedirect.ts b/src/utils/loginRedirect.ts index 0c6c65e..36ed178 100644 --- a/src/utils/loginRedirect.ts +++ b/src/utils/loginRedirect.ts @@ -3,6 +3,9 @@ import { AuthKindType } from '@/types' import { redirect } from 'next/navigation' -export async function loginRedirect(kind: AuthKindType) { +export async function loginRedirect(kind: AuthKindType, signed?: boolean) { + if (signed) { + return redirect(`/auth/login?kind=${kind}&signed=${signed}`) + } return redirect(`/auth/login?kind=${kind}`) }