Skip to content

Commit

Permalink
Merge pull request #29 from Pro-Pofol/feature/#15-Login&Signup
Browse files Browse the repository at this point in the history
Feature/#15 :: 회원가입 후 재로그인 제거
  • Loading branch information
wjknnn committed May 27, 2024
2 parents 981b05d + f3e832b commit 8d8c36f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
22 changes: 20 additions & 2 deletions src/app/auth/facebook/login/route.ts
Original file line number Diff line number Diff line change
@@ -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)
}
13 changes: 11 additions & 2 deletions src/app/auth/login/route.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion src/components/modal/SignupModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}

Expand Down
5 changes: 4 additions & 1 deletion src/services/authSignup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
5 changes: 4 additions & 1 deletion src/utils/loginRedirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}

0 comments on commit 8d8c36f

Please sign in to comment.