Skip to content

Commit

Permalink
Fix: header 로그인시 redirect기능 layout으로 옮기고, 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
nightowlzz committed May 28, 2024
1 parent 589d805 commit ccbd00b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 69 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

# page
page_bak.tsx
23 changes: 0 additions & 23 deletions app/(auth)/error.tsx

This file was deleted.

17 changes: 10 additions & 7 deletions app/(auth)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Loading from '@/components/loading/Loading';
import { ACCESS_TOKEN_KEY } from '@/lib/axios';
import { JoinBody, JoinWrap } from '@/styles/loginStyle';
import { redirect, useRouter } from 'next/navigation';
import { useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';

function getCookie(name: string) {
Expand All @@ -11,22 +11,25 @@ function getCookie(name: string) {
for (const cookie of cookies) {
const [cookieName] = cookie.split('=');
if (cookieName === name) {
redirect('/folder');
return true;
}
}
return false;
}

export default function Template({ children }: { children: React.ReactNode }) {
const [isLoading, setIsLoading] = useState(false);

getCookie(ACCESS_TOKEN_KEY);
const router = useRouter();
const [isLoading, setIsLoading] = useState(true);

useEffect(() => {
setIsLoading(true);
if (getCookie(ACCESS_TOKEN_KEY)) {
router.push('/folder');
return;
}
setIsLoading(false);
}, [isLoading]);

if (!isLoading) return <Loading />;
if (isLoading) return <Loading />;

return (
<JoinWrap className='no-header--container signup__wrap'>
Expand Down
26 changes: 5 additions & 21 deletions app/(auth)/signin/page.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
'use client';
import AuthLink from '@/components/Auth/AuthLink';
import AuthLogo from '@/components/Auth/AuthLogo';
import AuthRegister from '@/components/Auth/AuthRegister';
import Button from '@/components/common/atoms/Button';
import LinkButton from '@/components/common/atoms/LinkButton';
import { ErrorText, FormRowBox, FormWrap } from '@/components/join/formStyle';
import { loginForm } from '@/components/join/interface';
import Loading from '@/components/loading/Loading';
import { AuthContext } from '@/lib/auto.provider';
import { instance } from '@/lib/axios';
import { FontSM, Relative } from '@/styles/commonStyle';
import { Relative } from '@/styles/commonStyle';
import Image from 'next/image';
import { useRouter } from 'next/navigation';
import { useContext, useEffect, useState } from 'react';
import { useContext, useState } from 'react';
import { useForm } from 'react-hook-form';
import { JoinAccessControlBox, JoinBody, JoinSocial, JoinTitle, JoinWrap } from '../../../styles/loginStyle';
import { LINKBRARY_LOGO } from '@/src/constant/image.constant';
import AuthTitle from '@/components/Auth/AuthLogo';
import AuthLogo from '@/components/Auth/AuthLogo';
import AuthLink from '@/components/Auth/AuthLink';
import AuthRegister from '@/components/Auth/AuthRegister';

export default function SignIn() {
const router = useRouter();
const { handleLogin } = useContext(AuthContext);
const [IsVisibility, setIsVisibility] = useState(false);
const [isLoading, setIsLoading] = useState(false);

const {
register,
Expand Down Expand Up @@ -51,16 +45,6 @@ export default function SignIn() {
handleLoginCheck(email, password);
};

useEffect(() => {
if (localStorage.getItem('linkbrary')) {
alert('로그인한 상태입니다.');
router.push('/folder');
}
setIsLoading(true);
}, [router]);

if (!isLoading) return <Loading />;

return (
<>
<AuthLogo />
Expand Down
19 changes: 3 additions & 16 deletions app/(auth)/signup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import Button from '@/components/common/atoms/Button';
import LinkButton from '@/components/common/atoms/LinkButton';
import { ErrorText, FormRowBox, FormWrap } from '@/components/join/formStyle';
import { IJoinForm } from '@/components/join/interface';
import Loading from '@/components/loading/Loading';
import { instance } from '@/lib/axios';
import { LINKBRARY_LOGO } from '@/src/constant/image.constant';
import { FontSM, Relative } from '@/styles/commonStyle';
import Image from 'next/image';
import { useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';
import { useState } from 'react';
import { useForm } from 'react-hook-form';
import { JoinAccessControlBox, JoinBody, JoinSocial, JoinTitle, JoinWrap } from '../../../styles/loginStyle';
import { LINKBRARY_LOGO } from '@/src/constant/image.constant';
import { JoinAccessControlBox, JoinSocial, JoinTitle } from '../../../styles/loginStyle';

export default function SignUp() {
const router = useRouter();
Expand All @@ -22,9 +21,7 @@ export default function SignUp() {
handleSubmit,
formState: { errors },
setError,
setValue,
} = useForm<IJoinForm>({ mode: 'onBlur' });
const [isLoading, setIsLoading] = useState(false);

const handleEmailCheck = async (email: IJoinForm['email']) => {
try {
Expand Down Expand Up @@ -52,16 +49,6 @@ export default function SignUp() {
router.push('/folder');
};

useEffect(() => {
if (localStorage.getItem('linkbrary')) {
alert('로그인한 상태입니다.');
router.push('/folder');
}
setIsLoading(true);
}, [router]);

if (!isLoading) return <Loading />;

return (
<>
<JoinTitle>
Expand Down
4 changes: 3 additions & 1 deletion components/common/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ function Header() {
$position={isfixed}>
<HeaderInner>
<HeaderLogo className='head__logo'>
<Link href='/'>
<Link
href='/'
scroll={false}>
<Image
src={LINKBRARY_LOGO}
alt='linkbrary'
Expand Down
3 changes: 2 additions & 1 deletion components/common/atoms/LinkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export default function LinkButton({ children, href, linkClass, target = '_self'
<LinkModule
href={href}
className={linkClass}
target={target}>
target={target}
scroll={false}>
{children}
</LinkModule>
);
Expand Down

0 comments on commit ccbd00b

Please sign in to comment.