From 6154bd54a81dd8e85a24cedfcd57fc3042ffd622 Mon Sep 17 00:00:00 2001 From: corpi Date: Sat, 14 Mar 2026 00:48:24 +0900 Subject: [PATCH] =?UTF-8?q?fix(landing):=20=EC=9D=B8=EC=A6=9D=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=EC=97=90=20=EB=94=B0=EB=9D=BC=20CTA=20=EA=B2=BD?= =?UTF-8?q?=EB=A1=9C=20=EB=B6=84=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(landing)/page.tsx | 5 ++- .../components/AuthLandingLoginButton.tsx | 38 +++++++++++++++++++ .../auth/components/AuthRedirectButton.tsx | 15 +++++--- src/features/auth/model/hasClientAuth.ts | 13 +++++++ 4 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 src/features/auth/components/AuthLandingLoginButton.tsx create mode 100644 src/features/auth/model/hasClientAuth.ts diff --git a/src/app/(landing)/page.tsx b/src/app/(landing)/page.tsx index 4fd128e..69e9b52 100644 --- a/src/app/(landing)/page.tsx +++ b/src/app/(landing)/page.tsx @@ -1,5 +1,6 @@ import Link from "next/link"; import { copy } from '@/shared/i18n'; +import { AuthLandingLoginButton } from "@/features/auth/components/AuthLandingLoginButton"; import { AuthRedirectButton } from "@/features/auth/components/AuthRedirectButton"; import { Button } from "@/shared/ui/Button"; @@ -19,7 +20,9 @@ export default function MarketingPage() { diff --git a/src/features/auth/components/AuthLandingLoginButton.tsx b/src/features/auth/components/AuthLandingLoginButton.tsx new file mode 100644 index 0000000..25dee13 --- /dev/null +++ b/src/features/auth/components/AuthLandingLoginButton.tsx @@ -0,0 +1,38 @@ +'use client'; + +import type { ReactNode } from 'react'; +import { useAuthStore } from '@/entities/auth'; +import { Button, type ButtonSize, type ButtonVariant } from '@/shared/ui/Button'; +import { hasClientAuth } from '../model/hasClientAuth'; + +interface AuthLandingLoginButtonProps { + children: ReactNode; + className?: string; + size?: ButtonSize; + variant?: ButtonVariant; +} + +export function AuthLandingLoginButton({ + children, + className, + size = 'sm', + variant = 'ghost', +}: AuthLandingLoginButtonProps) { + const accessToken = useAuthStore((state) => state.accessToken); + const isAuthenticated = useAuthStore((state) => state.isAuthenticated); + + if ( + hasClientAuth({ + accessToken, + isAuthenticated, + }) + ) { + return null; + } + + return ( + + ); +} diff --git a/src/features/auth/components/AuthRedirectButton.tsx b/src/features/auth/components/AuthRedirectButton.tsx index 083ee0c..c0d49cf 100644 --- a/src/features/auth/components/AuthRedirectButton.tsx +++ b/src/features/auth/components/AuthRedirectButton.tsx @@ -1,11 +1,10 @@ 'use client'; -import Cookies from 'js-cookie'; import { useRouter } from 'next/navigation'; import type { ReactNode } from 'react'; import { useAuthStore } from '@/entities/auth'; -import { TOKEN_COOKIE_KEY } from '@/shared/config/authTokens'; import { Button, type ButtonSize, type ButtonVariant } from '@/shared/ui/Button'; +import { hasClientAuth } from '../model/hasClientAuth'; interface AuthRedirectButtonProps { children: ReactNode; @@ -21,7 +20,7 @@ export function AuthRedirectButton({ className, size = 'md', variant = 'primary', - authenticatedHref = '/space', + authenticatedHref = '/app', unauthenticatedHref = '/login', }: AuthRedirectButtonProps) { const router = useRouter(); @@ -29,8 +28,14 @@ export function AuthRedirectButton({ const isAuthenticated = useAuthStore((state) => state.isAuthenticated); const handleClick = () => { - const hasAccessToken = isAuthenticated || Boolean(accessToken) || Boolean(Cookies.get(TOKEN_COOKIE_KEY)); - router.push(hasAccessToken ? authenticatedHref : unauthenticatedHref); + router.push( + hasClientAuth({ + accessToken, + isAuthenticated, + }) + ? authenticatedHref + : unauthenticatedHref, + ); }; return ( diff --git a/src/features/auth/model/hasClientAuth.ts b/src/features/auth/model/hasClientAuth.ts new file mode 100644 index 0000000..796741f --- /dev/null +++ b/src/features/auth/model/hasClientAuth.ts @@ -0,0 +1,13 @@ +'use client'; + +import Cookies from 'js-cookie'; +import { TOKEN_COOKIE_KEY } from '@/shared/config/authTokens'; + +interface HasClientAuthInput { + accessToken: string | null; + isAuthenticated: boolean; +} + +export const hasClientAuth = ({ accessToken, isAuthenticated }: HasClientAuthInput) => { + return isAuthenticated || Boolean(accessToken) || Boolean(Cookies.get(TOKEN_COOKIE_KEY)); +};