feat(auth): 랜딩 시작 분기와 앱 라우트 가드를 추가

This commit is contained in:
2026-03-10 13:30:09 +09:00
parent 1c55f74132
commit 92a509ebb6
7 changed files with 848 additions and 68 deletions

View File

@@ -0,0 +1,47 @@
"use client";
import type { ReactNode } from "react";
import Cookies from "js-cookie";
import { useRouter } from "next/navigation";
import { TOKEN_COOKIE_KEY } from "@/features/auth/model/constants";
import { Button, type ButtonSize, type ButtonVariant } from "@/shared/ui/Button";
import { useAuthStore } from "@/store/useAuthStore";
interface AuthRedirectButtonProps {
children: ReactNode;
className?: string;
size?: ButtonSize;
variant?: ButtonVariant;
authenticatedHref?: string;
unauthenticatedHref?: string;
}
export function AuthRedirectButton({
children,
className,
size = "md",
variant = "primary",
authenticatedHref = "/space",
unauthenticatedHref = "/login",
}: AuthRedirectButtonProps) {
const router = useRouter();
const accessToken = useAuthStore((state) => state.accessToken);
const isAuthenticated = useAuthStore((state) => state.isAuthenticated);
const handleClick = () => {
const hasAccessToken = isAuthenticated || Boolean(accessToken) || Boolean(Cookies.get(TOKEN_COOKIE_KEY));
router.push(hasAccessToken ? authenticatedHref : unauthenticatedHref);
};
return (
<Button
type="button"
variant={variant}
size={size}
className={className}
onClick={handleClick}
>
{children}
</Button>
);
}

View File

@@ -0,0 +1,2 @@
export const TOKEN_COOKIE_KEY = "vr_access_token";
export const REFRESH_TOKEN_COOKIE_KEY = "vr_refresh_token";