Skip to content

Commit

Permalink
Merge branch 'feat/#3_splash_socialAuth' of https://github.com/KUSITM…
Browse files Browse the repository at this point in the history
…S-30th-TEAM-C/frontend into init/#6-tdd_storybook_setting
  • Loading branch information
nebulaBdj committed Oct 27, 2024
2 parents b185272 + 0dcb60d commit e596a12
Show file tree
Hide file tree
Showing 14 changed files with 511 additions and 5 deletions.
Binary file added public/images/google-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/kakao-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/naver-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 85 additions & 0 deletions src/app/auth/callback/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
'use client'

import { Suspense, useEffect } from 'react'
import { useSearchParams, useRouter } from 'next/navigation'
import { SendData } from './type'

function LoginCheck() {
const searchParams = useSearchParams()
const router = useRouter()

const code = searchParams.get('code')
const scope = searchParams.get('scope')
const state = searchParams.get('state')

const sendUserHomeOrStart = (userState: string) => {
if (userState === 'GUEST') router.push('/start')
if (userState === 'MEMBER') router.push('/home')
}

const getUserData = async (socialType: string, sendDataArr: SendData[]) => {
let url: string = `https://cnergy.p-e.kr/v1/oauth/login/${socialType}?`
for (let i = 0; i < sendDataArr.length; i += 1) {
if (i === 0) {
url += `${sendDataArr[i].name}=${sendDataArr[i].value}`
}

if (i !== 0) {
url += `&${sendDataArr[i].name}=${sendDataArr[i].value}`
}
}

try {
const res = await fetch(url, {
method: 'GET',
})

if (!res.ok) {
throw new Error(`HTTP error! status: ${res.status}`)
}

const data = await res.json()

// console.log('reponse Data', data)

// 토근 설정
localStorage.setItem('accessToken', data.data.accessToken)
localStorage.setItem('refreshToken', data.data.refreshToken)

// role에 따라 페이지 이동 차이
sendUserHomeOrStart(data.data.role)
} catch (error) {
console.log('Error fetching user data', error)
}
}

useEffect(() => {
const sendDataArr: SendData[] = []

if (code) {
if (state) {
sendDataArr.push({ name: 'code', value: code })
sendDataArr.push({ name: 'state', value: state })
getUserData('naver', sendDataArr)
return
}
if (scope) {
sendDataArr.push({ name: 'code', value: code })
getUserData('google', sendDataArr)
return
}
sendDataArr.push({ name: 'code', value: code })
getUserData('kakao', sendDataArr)
}
}, [code, state, scope])

return <div>로그인 정보를 확인중입니다...</div>
}

export default function WrappedLoginCheck() {
return (
<Suspense fallback={<div>로딩 중...</div>}>
<LoginCheck />
</Suspense>
)
}
4 changes: 4 additions & 0 deletions src/app/auth/callback/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface SendData {
name: string
value: string
}
30 changes: 30 additions & 0 deletions src/app/components/Oauth/OauthBtn.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useRouter } from 'next/navigation'
import { OauthBtnProps } from './type'

export default function OauthBtn({ auth_uri, type, text }: OauthBtnProps) {
const router = useRouter()

const handleSocialLogin = async () => {
router.push(`${auth_uri}`)
}

let btnStyle: string = ''

if (type === 'kakao') btnStyle = 'bg-[#FFE819]'
if (type === 'naver') btnStyle = 'bg-[#03C75A]'
if (type === 'google') btnStyle = 'bg-white border'

return (
<button
onClick={() => handleSocialLogin()}
type="button"
className={`
${btnStyle}
w-[342px] h-[56px] flex justify-center items-center rounded-12 text-black font-semibold mb-10
`}
>
<img src={`/images/${type}-icon.png`} alt={`${type}`} className="mr-8" />
{text}로 시작하기
</button>
)
}
22 changes: 22 additions & 0 deletions src/app/components/Oauth/SocialTypeData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { OauthBtnData } from './type'

export const socialTypes: OauthBtnData[] = [
{
id: 1,
type: 'kakao',
text: '카카오',
auth_uri: 'https://cnergy.p-e.kr/v1/oauth/kakao',
},
{
id: 2,
type: 'naver',
text: '네이버',
auth_uri: 'https://cnergy.p-e.kr/v1/oauth/naver',
},
{
id: 3,
type: 'google',
text: '구글',
auth_uri: 'https://cnergy.p-e.kr/v1/oauth/google',
},
]
8 changes: 8 additions & 0 deletions src/app/components/Oauth/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface OauthBtnData {
id: number
type: string
text: string
auth_uri: string
}

export type OauthBtnProps = Omit<OauthBtnData, 'id'>
3 changes: 3 additions & 0 deletions src/app/home/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Home() {
return <div>홈페이지여</div>
}
100 changes: 98 additions & 2 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,103 @@
'use client'

import { useEffect, useState } from 'react'
import { motion } from 'framer-motion'
import SplashLogo from '@/components/Icons/SplashLogo'
import SplashTop from '@/components/Icons/SplashTop'
import SplashBottom from '@/components/Icons/SplashBottom'
import { socialTypes } from './components/Oauth/SocialTypeData'
import OauthBtn from './components/Oauth/OauthBtn'

export default function Home() {
const [isSplash, setIsSplash] = useState(true)
const [logoColor, setlogoColor] = useState('white')
const [splashBoxColor, setSplashBoxColor] = useState('#31313B')

useEffect(() => {
const timer = setTimeout(() => {
setIsSplash(false)
setSplashBoxColor('#F3F3F4')
}, 1000)

const logotimer = setTimeout(() => {
setlogoColor('#1A1A25')
}, 1700)

return () => {
clearTimeout(timer)
clearTimeout(logotimer)
}
}, [])

return (
<div className="text-[#444444] flex justify-center items-center h-screen">
hi~
<div className=" flex justify-center items-center w-screen h-screen">
<motion.div
className=" relative w-full h-full bg-primary_foundation_100"
initial={{ opacity: 1 }}
animate={{
opacity: 1,
backgroundColor: isSplash ? '#1A1A25' : '#ffffff',
}}
transition={{ duration: 0.5 }}
>
<SplashLogo
className="absolute left-[127px] top-[248px] z-50"
firstPieceColor={logoColor}
/>

<motion.div
initial={{ x: 0, y: -200, opacity: 1 }}
animate={{ x: 0, y: -17, opacity: 1 }}
transition={{ duration: 0.5 }}
>
<SplashTop
elementColor={splashBoxColor}
className="absolute right-0 top-[186px]"
/>
</motion.div>

<motion.div
initial={{ x: 0, y: 553, opacity: 1 }}
animate={{
x: 0,
y: 264,
opacity: 1,
backgroundColor: splashBoxColor,
}}
transition={{ duration: 0.5 }}
>
<SplashBottom
elementColor={splashBoxColor}
className="absolute left-0"
/>
</motion.div>
</motion.div>
{!isSplash && (
<>
<p className="z-50 font-semibold absolute top-[388px]">
여기에는 캐치프레이즈가 들어갑니다
</p>

<motion.div
className="absolute bottom-80"
initial={{ y: 300, opacity: 0 }}
animate={{ y: 0, opacity: 1 }}
transition={{ duration: 0.5 }}
>
{socialTypes &&
socialTypes.map((socialData) => {
return (
<OauthBtn
key={socialData.id}
type={socialData.type}
text={socialData.text}
auth_uri={socialData.auth_uri}
/>
)
})}
</motion.div>
</>
)}
</div>
)
}
29 changes: 29 additions & 0 deletions src/components/Icons/SplashBottom.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { SVGProps } from 'react'

interface SplashBottomProps extends SVGProps<SVGSVGElement> {
elementColor?: string
}

export default function SplashBottom({
elementColor = '#F3F3F4',
...props
}: SplashBottomProps) {
return (
<svg
width="292"
height="291"
viewBox="0 0 292 291"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<rect y="194" width="97" height="97" fill={elementColor} />
<rect y="97" width="97" height="97" fill={elementColor} />
<rect x="97" y="194" width="98" height="97" fill={elementColor} />
<rect x="97" y="97" width="98" height="97" fill={elementColor} />
<rect x="97" width="98" height="97" fill={elementColor} />
<rect x="195" y="194" width="97" height="97" fill={elementColor} />
<rect width="98" height="97" fill={elementColor} />
</svg>
)
}
Loading

0 comments on commit e596a12

Please sign in to comment.