Skip to content

Commit

Permalink
Merge pull request #53 from primus-teoSprint/feat/#26
Browse files Browse the repository at this point in the history
[#26] ์†Œ์…œ๋กœ๊ทธ์ธ ๊ตฌํ˜„
  • Loading branch information
hanseulhee authored Apr 8, 2024
2 parents 0e09566 + 233410b commit 7c34598
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 28 deletions.
39 changes: 31 additions & 8 deletions app/(route)/oauth/callback/kakao/_components/callback/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
'use client'

import { useSearchParams } from 'next/navigation'
import React, { useEffect } from 'react'
import Loading from '@/app/_common/loading'
import { userKakaoTokenAtom } from '@/app/_store/atom'
import axiosInstance from '@/app/_utils/axios'
import { useRouter, useSearchParams } from 'next/navigation'
import { useEffect } from 'react'
import { useRecoilState } from 'recoil'

function Callback() {
const router = useRouter()
const params = useSearchParams()
const codeParam = params.get('code')
const [, setLoginUser] = useRecoilState(userKakaoTokenAtom)

useEffect(() => {
const codeParam = params.get('code')
async function postOAuth(code: string) {
const response = await axiosInstance.post(`api/auth/kakao/signin`, {
code,
})

return response
}

if (codeParam) {
console.log(codeParam)
useEffect(() => {
const handleLogin = async () => {
if (codeParam) {
try {
const data = await postOAuth(codeParam)
localStorage.setItem('accessToken', data.data.token)
setLoginUser(data.data.token)
router.push('/main')
} catch (error) {
console.error('์ธ์ฆ ์ฝ”๋“œ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.')
}
}
}
}, [params])
handleLogin()
}, [])

return <div>Redirecting...</div>
return <Loading />
}

export default Callback
9 changes: 4 additions & 5 deletions app/(route)/oauth/callback/kakao/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React, { Suspense } from 'react'
import Loading from '@/app/_common/loading'
import { Suspense } from 'react'
import Callback from './_components/callback'

function page() {
return (
<Suspense fallback={<div>๋กœ๋”ฉ์ค‘...</div>}>
<div>
<Callback />
</div>
<Suspense fallback={<Loading />}>
<Callback />
</Suspense>
)
}
Expand Down
16 changes: 14 additions & 2 deletions app/(route)/signin/_components/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,22 @@ function Login() {

const handleLogin = () => {
const KAKAO_CLIENT_ID = process.env.NEXT_PUBLIC_KAKAO_CLIENT_ID
const KAKAO_REDIRECT_URL = process.env.NEXT_PUBLIC_KAKAO_REDIRECT_URL

let KAKAO_REDIRECT_URL

if (process.env.NODE_ENV === 'development') {
KAKAO_REDIRECT_URL = process.env.NEXT_PUBLIC_KAKAO_DEVLOP_REDIRECT_URL
} else {
KAKAO_REDIRECT_URL = process.env.NEXT_PUBLIC_KAKAO_REDIRECT_URL
}

const kakadoAuthUrl = `https://kauth.kakao.com/oauth/authorize?client_id=${KAKAO_CLIENT_ID}&redirect_uri=${KAKAO_REDIRECT_URL}&response_type=code`

window.location.href = kakadoAuthUrl
try {
router.push(kakadoAuthUrl)
} catch (error) {
console.log(error)
}
}

return (
Expand Down
15 changes: 7 additions & 8 deletions app/(route)/verification/ibulsin/_components/Step3/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
'use client'

import React from 'react'
import Link from 'next/link'
import MoreExplainBtn from '../MoreExplainBtn'
import { ibulsinVariants } from '@/app/_constants/ibulsin'
import useIbulsinData from '@/app/_hooks/useIbulsinData'
import useIbulsinFormMutation from '@/app/_service/mutations/useIbulsinForm'
import {
pretotypingTextareaAtom,
xyzTextareaAtom,
} from '@/app/_store/ibulsin/textarea'
import useIbulsinData from '@/app/_hooks/useIbulsinData'
import Link from 'next/link'
import { useRouter } from 'next/navigation'
import MoreExplainBtn from '../MoreExplainBtn'
import Textarea from '../Textarea'
import S from './index.module.css'
import useIbulsinFormMutation from '@/app/_service/mutations/useIbulsinForm'
import { useRouter } from 'next/navigation'

function Step3() {
const router = useRouter()
Expand Down Expand Up @@ -46,10 +45,10 @@ function Step3() {

mutate(body, {
onSuccess: () => {
router.push('/')
router.push('/indicators')
},
onError: () => {
alert('์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์Šต๋‹ˆ๋‹ค.')
router.push('/signin')
},
})
}
Expand Down
5 changes: 3 additions & 2 deletions app/_common/loading/loading.module.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
.wrapper {
position: fixed;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: fixed;

top: 0;
width: 480px;
min-height: 100vh;
height: auto;
color: white;
font-size: 1.4rem;
letter-spacing: 0.2px;
margin-top: 10px;
background-color: var(--purple-700);
}
9 changes: 9 additions & 0 deletions app/_store/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,25 @@ export interface ActiveInvestmentItemType {

// type ActiveType = Omit<ActiveInvestmentItemType, 'id'>

// ์นด์นด์˜ค ์œ ์ € ํ† ํฐ
export const userKakaoTokenAtom = atom<string>({
key: 'userKakaoTokenAtom',
default: '',
})

// ์ง€ํ‘œ ๊ฒฐ๊ณผ
export const resultAtom = atom<number>({
key: 'resultAtom',
default: 0,
})

// ์ ๊ทน์  ํˆฌ์ž ์ง€ํ‘œ ์‚ฌ์šฉ์ž๊ฐ€ ์„ ํƒํ•œ ํ•ญ๋ชฉ
export const selectedItemAtom = atom<ActiveInvestmentItemType | null>({
key: 'selectedItemAtom',
default: null,
})

// ์ ๊ทน์  ํˆฌ์ž ์ง€ํ‘œ ์ „์ฒด ์‚ฌ์šฉ์ž ์ˆ˜
export const totalinputValueAtom = atom({
key: 'totalinputValueAtom',
default: '',
Expand Down
6 changes: 3 additions & 3 deletions app/_utils/provider.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use client'

import React from 'react'
import { QueryClientProvider, QueryClient } from '@tanstack/react-query'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import { ReactQueryStreamedHydration } from '@tanstack/react-query-next-experimental'
import React, { useState } from 'react'

function Providers({ children }: React.PropsWithChildren) {
const [client] = React.useState(
const [client] = useState(
new QueryClient({
defaultOptions: {
queries: {
Expand Down

0 comments on commit 7c34598

Please sign in to comment.