Skip to content

Commit

Permalink
Merge pull request #25 from Pro-Pofol/feature/#15-Login&Signup
Browse files Browse the repository at this point in the history
Feature/#15 :: Kakao auth 연동 완료
  • Loading branch information
wjknnn authored May 22, 2024
2 parents 5c3ffbc + 973aefa commit d7f97f3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 34 deletions.
13 changes: 1 addition & 12 deletions src/app/auth/google/login/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,7 @@ export async function GET(request: Request) {
.then((response) => response.json())
.then(async (data) => {
return await authLogin('google', data.access_token)
.then((response) => {
const setCookie = response.headers['set-cookie']
cookies().set({
name: 'RF-TOKEN',
value: setCookie?.[0].split(';')[0].split('=')[1] as string,
httpOnly: true,
secure: true,
path: '/',
sameSite: 'strict',
})
return NextResponse.redirect(requestUrl.origin)
})
.then(() => NextResponse.redirect(requestUrl.origin))
.catch((error) => {
cookies().set('Access_Token', data.access_token)
return NextResponse.redirect(
Expand Down
13 changes: 1 addition & 12 deletions src/app/auth/kakao/login/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,7 @@ export async function GET(request: Request) {
if (code) {
return getKakaoToken(code).then(async (data) => {
return await authLogin('kakao', data.access_token)
.then((response) => {
const setCookie = response.headers['set-cookie']
cookies().set({
name: 'RF-TOKEN',
value: setCookie?.[0].split(';')[0].split('=')[1] as string,
httpOnly: true,
secure: true,
path: '/',
sameSite: 'strict',
})
return NextResponse.redirect(requestUrl.origin)
})
.then((response) => NextResponse.redirect(requestUrl.origin))
.catch((error) => {
cookies().set('Access_Token', data.access_token)
return NextResponse.redirect(`${requestUrl.origin}/signup?kind=kakao`)
Expand Down
11 changes: 5 additions & 6 deletions src/components/modal/SignupModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { Button } from '../Button'
import { Input } from '../Input'
import { Select } from '../Select'
import Link from 'next/link'
import { AuthSignupType } from '@/types'
import { AuthKindType, AuthSignupType } from '@/types'
import { authSignup } from '@/services'
import { getCookie } from '@/utils'
import { getCookie, loginRedirect } from '@/utils'

const option = [
{ value: '1', name: 'Backend' },
Expand All @@ -34,10 +34,9 @@ export const SignupModal = ({ kind }: { kind: string }) => {
major: major,
}
const access_token = getCookie('Access_Token')
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-expect-error
const token = await authSignup(kind, access_token, signupJson)
console.log(token)
await authSignup(kind as AuthKindType, access_token || '', signupJson).then(
() => loginRedirect(kind as AuthKindType),
)
}

return (
Expand Down
16 changes: 16 additions & 0 deletions src/services/authLogin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use server'

import { AuthKindType } from '@/types'
import { instance } from './interceptor'
import { cookies } from 'next/headers'

export const authLogin = async (kind: AuthKindType, token: string) => {
return await instance({
Expand All @@ -8,5 +11,18 @@ export const authLogin = async (kind: AuthKindType, token: string) => {
headers: {
'OA-TOKEN': token,
},
}).then((response) => {
const access_token = response.headers['authorization']
const setCookie = response.headers['set-cookie']
cookies().set({
name: 'RF-TOKEN',
value: setCookie?.[0].split(';')[0].split('=')[1] as string,
httpOnly: true,
secure: true,
path: '/',
sameSite: 'strict',
})
cookies().set('access_token', access_token.split(' ')[1])
return response
})
}
5 changes: 1 addition & 4 deletions src/services/getKakaoToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ export const getKakaoToken = async (code: string) => {
code: code,
},
})
.then((res) => {
console.log(`[[[data is ${res}]]]`)
return res.data
})
.then((res) => res.data)
.catch((error) => console.log(error))
}

0 comments on commit d7f97f3

Please sign in to comment.