Skip to content

Commit

Permalink
Fix: 에러 해결 (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjg729729 authored Oct 1, 2024
2 parents efc4462 + 053b14d commit 0e254d4
Show file tree
Hide file tree
Showing 27 changed files with 349 additions and 55 deletions.
2 changes: 2 additions & 0 deletions app/(route)/(header)/(auth)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client'

import Image from 'next/image'
import React, { ReactNode } from 'react'

Expand Down
6 changes: 5 additions & 1 deletion app/(route)/(header)/(auth)/login/email/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { signIn } from 'next-auth/react'
import React, { ChangeEventHandler, FormEvent, ReactNode, useState } from 'react'

import EmailLink from '@/components/auth/EmailLink'
import PasswordFindLink from '@/components/auth/PasswordFindLink'
import { TextDivider } from '@/components/common/Dividers'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
Expand Down Expand Up @@ -112,7 +113,10 @@ const EmailLoginPage = ({}: EmailLoginPageProps): ReactNode => {
<Button type='submit' variant='tbPrimary' className='mt-2 h-13 w-full'>
로그인
</Button>
<EmailLink className='mt-2' />
<div>
<PasswordFindLink className='my-2' />
<EmailLink />
</div>
</div>
</form>
</div>
Expand Down
41 changes: 26 additions & 15 deletions app/(route)/(header)/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import React, { ReactNode } from 'react'
import EmailLink from '@/components/auth/EmailLink'
import { TextDivider } from '@/components/common/Dividers'
import { Button } from '@/components/ui/button'
import { ClientModalData } from '@/lib/constants/errors'
import { ROUTES } from '@/lib/constants/routes'
import useModal from '@/lib/utils/hooks/useModal'

type SocialLoginButton = {
variant: 'kakao' | 'naver' | 'google' | 'tbPrimary'
Expand Down Expand Up @@ -46,8 +48,14 @@ const LOGIN_BUTTONS: Array<SocialLoginButton> = [

const LoginPage = (): ReactNode => {
const router = useRouter()
const { modalData, handleModalStates, Modal } = useModal()

const onClickLoginBtn = async (provider: string): Promise<void> => {
if (provider === 'naver') {
handleModalStates(ClientModalData.naverLoginDenied, 'open') // router.refresh()
return
}

if (provider === 'credentials') {
router.push(ROUTES.AUTH.EMAIL_LOGIN.url)
} else {
Expand All @@ -62,23 +70,26 @@ const LoginPage = (): ReactNode => {
</div>

<div className='flex flex-col items-center gap-5'>
{LOGIN_BUTTONS.map(button => (
<Button
key={button.name}
variant={button.variant}
className='flex h-13 w-full items-center justify-center gap-14 pl-4'
onClick={() => onClickLoginBtn(button.auth)}
>
{button.ImageSrc ? (
<Image src={button.ImageSrc} width={24} height={24} alt={button.name} />
) : (
<Mail size={24} />
)}
{button.name}
</Button>
))}
{LOGIN_BUTTONS.map(button => {
return (
<Button
key={button.name}
variant={button.variant}
className='flex h-13 w-full items-center justify-center gap-14 pl-4'
onClick={() => onClickLoginBtn(button.auth)}
>
{button.ImageSrc ? (
<Image src={button.ImageSrc} width={24} height={24} alt={button.name} />
) : (
<Mail size={24} />
)}
{button.name}
</Button>
)
})}
</div>
<EmailLink className='mt-12 w-full text-center' />
<Modal onConfirm={() => {}} />
</div>
)
}
Expand Down
113 changes: 111 additions & 2 deletions app/(route)/(header)/(auth)/signout/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,118 @@
import React, { ReactNode } from 'react'
'use client'

import { useRouter } from 'next/navigation'
import { useSession } from 'next-auth/react'
import React, { ReactNode, useState } from 'react'

import { TextDivider } from '@/components/common/Dividers'
import { Button } from '@/components/ui/button'
import { Checkbox } from '@/components/ui/checkbox'
import { ClientModalData } from '@/lib/constants/errors'
import { BACKEND_ROUTES } from '@/lib/constants/routes'
import useModal from '@/lib/utils/hooks/useModal'
import { useToast } from '@/lib/utils/hooks/useToast'

interface SignOutPageProps {}

const SignOutPage = ({}: SignOutPageProps): ReactNode => {
return <div>SignOutPage</div>
const { modalData, handleModalStates, Modal } = useModal()
const session: any = useSession()
const router = useRouter()
const [isChecked, setIsChecked] = useState<boolean>(false)
const { toast } = useToast()

const signOut = async () => {
if (!isChecked) {
console.log('431')

toast({ title: '주의사항에 동의해주세요.' })
return
}

const url = BACKEND_ROUTES.AUTH.SIGNOUT
try {
const res = await fetch(`/server${url.url}`, {
method: url.method,
headers: {
Authorization: session.data.accessToken,
'Content-Type': 'application/json',
},
credentials: 'include',
})

const status = res.status
if (res.ok) {
handleModalStates(
{
id: 'info',
title: '회원 탈퇴',
description: '회원 탈퇴가 완료되었습니다.',
isError: false,
},
'open',
)

return
}
switch (status) {
default:
handleModalStates(ClientModalData.serverError, 'open')
return
}
} catch (error) {
handleModalStates(ClientModalData.serverError, 'open')
}
}

return (
<div className='w-3/4 xl:w-3/5 2xl:w-1/2'>
<div className='my-10 flex items-center justify-center'>
<TextDivider text='회원탈퇴' />
</div>
<div className='flex flex-col items-center text-center text-lg'>
<h1 className='mb-4 text-3xl'>TraBook과 함께했던</h1>
<h1 className='mb-4 text-3xl'>소중한 여행 기록들을 간직해주세요!</h1>
<ul className='max-w-[450px] list-disc text-start'>
<li className='my-4'>서비스 이용 정보 (내 계힉, 보관함 등)은 모두 삭제됩니다.</li>
<li className='my-4'>기록된 리뷰 및 댓글은 삭제되지 않습니다.</li>
<li className='my-4'>회원가입 탈퇴 시 계정 정보는 영구 삭제됩니다.</li>
</ul>
<div className='my-6 flex max-w-[500px] items-center'>
<Checkbox
id='signup'
className='h-5 w-5 border-tbGray data-[state=checked]:bg-tbSecondary data-[state=checked]:text-tbPrimary'
checked={isChecked}
onClick={() => setIsChecked(prev => !prev)}
/>
<label
htmlFor='signup'
className='grow pl-2 text-lg font-normal leading-5 peer-disabled:cursor-not-allowed peer-disabled:opacity-70'
>
위 주의사항을 모두 숙제하였으며, 탈퇴에 동의합니다.
</label>
</div>
</div>
<div className='my-7 flex w-full gap-3'>
<Button variant='tbRed' className='h-14 w-1/2 text-lg' onClick={signOut}>
탈퇴하기
</Button>
<Button
variant='tbPrimary'
className='h-14 w-1/2 text-lg'
onClick={() => {
router.back()
}}
>
함께하기
</Button>
<Modal
onConfirm={() => {
router.push('/')
}}
/>
</div>
</div>
)
}

export default SignOutPage
37 changes: 37 additions & 0 deletions app/(route)/(header)/community/companion/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use client'

import { useRouter } from 'next/navigation'
import React, { ReactNode, useEffect } from 'react'

import useModal from '@/lib/utils/hooks/useModal'

interface CompanionPageProps {}

const CompanionPage = ({}: CompanionPageProps): ReactNode => {
const router = useRouter()
const { modalData, handleModalStates, Modal } = useModal()

useEffect(() => {
handleModalStates(
{
id: 'info',
title: '동행 구하기',
description: '서비스 준비 중입니다.',
isError: false,
},
'open',
)
}, [])

return (
<>
<Modal
onConfirm={() => {
router.replace('/login')
}}
/>
</>
)
}

export default CompanionPage
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const CommunityPlaceDetail = async ({ params }: CommunityPlaceDetailProps): Prom

return (
<div className='fixed inset-0 z-10 flex items-center justify-center bg-black bg-opacity-40'>
<div className='relative flex h-4/5 w-3/5 min-w-[600px] flex-col rounded-[30px] border-[1px] border-black bg-white'>
<div className='relative flex h-[95%] w-[90%] min-w-[600px] flex-col rounded-[30px] border-[1px] border-black bg-white'>
<PlaceDetail place={detailPlace} />
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const CommunityPlaceDetail = async ({ params }: CommunityPlaceDetailProps): Prom

return (
<div className='fixed inset-0 z-10 flex items-center justify-center bg-black bg-opacity-40'>
<div className='relative flex h-4/5 w-3/5 min-w-[600px] flex-col rounded-[30px] border-[1px] border-black bg-white'>
<div className='relative flex h-[95%] w-[90%] min-w-[600px] flex-col rounded-[30px] border-[1px] border-black bg-white'>
<PlaceDetail place={detailPlace} />
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
kakao(LOGIN_API_KEYS.kakao),
naver(LOGIN_API_KEYS.naver),
],
session: {
maxAge: 60 * 60 * 24 - 10,
},
callbacks: {
signIn: async ({ user, account }: { user: any; account: any }) => {
// console.log('account', account)
Expand Down
2 changes: 1 addition & 1 deletion components/Header/CommunityMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const CommunityMenu = ({ className }: CommunityMenuProps): ReactNode => {
<ToggleWrapper
isOpen={isOpen}
ref={ref}
className='absolute right-[-140%] top-3/4 flex items-center justify-evenly gap-2 rounded-lg bg-tbPrimary px-4 py-2'
className='absolute right-[-140%] top-3/4 flex items-center justify-center gap-2 rounded-lg bg-tbSecondaryHover px-2 py-2'
>
{NavSections.map(section => (
<Link
Expand Down
29 changes: 29 additions & 0 deletions components/Header/MobileMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
'use client'
import Link from 'next/link'
import { useRouter } from 'next/navigation'
import { Session } from 'next-auth'
import { signOut } from 'next-auth/react'
import React, { ReactNode } from 'react'

import { Button } from '@/components/ui/button'
import { ClientModalData } from '@/lib/constants/errors'
import { Route, ROUTES } from '@/lib/constants/routes'
import LucideIcon from '@/lib/icons/LucideIcon'
import { cn } from '@/lib/utils/cn'
import useModal from '@/lib/utils/hooks/useModal'
import ToggleWrapper, { useDropdown } from '@/lib/utils/hooks/useToggle'
import { Nullable } from '@/lib/utils/typeUtils'

Expand Down Expand Up @@ -60,8 +64,15 @@ const MY_SECTION_CREDENTIALS: NavSection = {
}

const MobileMenu = ({ session, className }: MobileMenuProps): ReactNode => {
const { modalData, handleModalStates, Modal } = useModal()
const { ref, isOpen, toggleDropdown } = useDropdown() // 드롭다운 상태 관리
const s: any = session
const router = useRouter()

const onClickLogOut = () => {
toggleDropdown()
handleModalStates(ClientModalData.logOutSuccess, 'open')
}

/**
* 각 Session 상수에 대한 Link를 렌더링합니다
Expand Down Expand Up @@ -110,7 +121,25 @@ const MobileMenu = ({ session, className }: MobileMenuProps): ReactNode => {
{renderNavLinks(COMMUNITY_SECTION)}
<Divider />
{s?.provider === 'credentials' ? renderNavLinks(MY_SECTION_CREDENTIALS) : renderNavLinks(MY_SECTION_SOCIAL)}
{s && (
<>
<Divider />
<div className='w-full p-4 hover:cursor-pointer' onClick={onClickLogOut}>
<div className='flex h-8 items-center justify-between'>
<span>로그아웃</span>

<LucideIcon name='ChevronRight' />
</div>
</div>
</>
)}
</ToggleWrapper>
<Modal
onConfirm={async () => {
await signOut()
router.push('/')
}}
/>
</>
)
}
Expand Down
2 changes: 1 addition & 1 deletion components/auth/EmailLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ROUTES } from '@/lib/constants/routes'
import { cn } from '@/lib/utils/cn'

interface EmailLinkProps {
className: string
className?: string
}

const EmailLink = ({ className }: EmailLinkProps): ReactNode => {
Expand Down
38 changes: 38 additions & 0 deletions components/auth/PasswordFindLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { ReactNode } from 'react'

import { cn } from '@/lib/utils/cn'
import useModal from '@/lib/utils/hooks/useModal'

interface PasswordFindLinkProps {
className?: string
}

const PasswordFindLink = ({ className }: PasswordFindLinkProps): ReactNode => {
const { modalData, handleModalStates, Modal } = useModal()
const openModal = () => {
handleModalStates(
{
id: 'info',
title: '비밀번호 찾기',
description: '서비스 준비 중입니다.\nTraBook 이메일로 문의해주세요.',
isError: false,
},
'open',
)
}

return (
<div className={cn('flex flex-col items-center justify-center gap-3 ssm:flex-row', className)}>
<p className='text-tbGray'>비밀번호를 잊으셨나요?</p>
{/* <Link className='text-black underline hover:text-tbBlue' href={ROUTES.AUTH.SIGNUP.url}>
비밀번호 찾기
</Link> */}
<div className='text-black underline hover:text-tbBlue' onClick={openModal}>
비밀번호 찾기
</div>
<Modal onConfirm={() => {}} />
</div>
)
}

export default PasswordFindLink
Loading

0 comments on commit 0e254d4

Please sign in to comment.