Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/(auth)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const metadata = makePageMetadata({
export default function AuthLayout({ children }: AuthCommonProps) {
return (
<div className="flex items-center justify-center min-h-screen bg-background">
<div className="flex flex-col gap-20 w-full max-w-[500px]">{children}</div>
<div className="flex flex-col gap-10 w-full max-w-[450px] mx-10">{children}</div>
</div>
);
}
13 changes: 5 additions & 8 deletions src/app/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { AuthHeader } from "@/components/auth/AuthHeader";
import { AuthMain } from "@/components/auth/AuthMain";
import { LoginForm } from "@/components/auth/login/LoginForm";
import { LoginPageTitle } from "@/components/auth/login/LoginPageTitle";
import { LoginSubtitle } from "@/components/auth/login/LoginSubtitle";
import { makePageMetadata } from "@/seo/metadata";
Expand All @@ -20,14 +22,9 @@ export default function LoginPage() {
<LoginSubtitle />
</AuthHeader>

<main>
{/* TODO: ๋‚˜์ค‘์— LoginMain + AuthCard + LoginForm ๊ตฌ์กฐ๋กœ ํ™•์žฅ */}
<div className="rounded-2xl bg-[var(--color-white)] px-6 py-8 shadow-[var(--shadow-md)]">
<p className="t-14-m text-[var(--color-gray-600)]">
์—ฌ๊ธฐ์—๋Š” ๋กœ๊ทธ์ธ ํผ์ด ๋“ค์–ด๊ฐˆ ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.
</p>
</div>
</main>
<AuthMain>
<LoginForm />
</AuthMain>
</>
);
}
4 changes: 2 additions & 2 deletions src/components/auth/AuthHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import type { AuthCommonProps } from "@/types/auth";

export function AuthHeader({ children }: AuthCommonProps) {
return (
<header className="flex flex-col items-center text-center gap-2">
<header className="flex flex-col items-center text-center gap-3">
<AppLogo />
<div className="space-y-3">{children}</div>
<div>{children}</div>
</header>
);
}
9 changes: 9 additions & 0 deletions src/components/auth/AuthMain.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { AuthCommonProps } from "@/types/auth";

export function AuthMain({ children }: AuthCommonProps) {
return (
<main className="w-full" aria-label="์ธ์ฆ ๋ณธ๋ฌธ">
{children}
</main>
);
}
172 changes: 172 additions & 0 deletions src/components/auth/login/LoginForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
"use client";

import { cn } from "@/lib/utils";
import { Button } from "@/shared/button";
import { Icon } from "@/shared/Icon";
import { Input } from "@/shared/input";
import { useAuthFormStore } from "@/stores/authForm.store";
import Link from "next/link";
import type { ChangeEvent, FormEvent } from "react";

export function LoginForm() {
const {
email,
password,
emailError,
passwordError,
isPasswordVisible,
setEmail,
setPassword,
clearEmailError,
clearPasswordError,
togglePasswordVisible,
validateLogin,
} = useAuthFormStore();

const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault(); // ๊ธฐ๋ณธ form submit ๋™์ž‘ ๋ง‰๊ธฐ

const isValid = validateLogin();
if (!isValid) {
// ์—๋Ÿฌ ์ƒํƒœ/๊ฐ’ ์ดˆ๊ธฐํ™”๋Š” ์Šคํ† ์–ด์—์„œ ์ด๋ฏธ ์ฒ˜๋ฆฌ
return;
}

// TODO: ์‹ค์ œ ๋กœ๊ทธ์ธ ์š”์ฒญ ๋กœ์ง
// ex) await login({ email, password });
};

const handleEmailChange = (event: ChangeEvent<HTMLInputElement>) => {
setEmail(event.target.value);
};

const handlePasswordChange = (event: ChangeEvent<HTMLInputElement>) => {
setPassword(event.target.value);
};

return (
<form
className={cn(
"flex flex-col gap-10 rounded-2xl border border-[var(--color-gray-200)] bg-[var(--color-white)] px-4 py-6",
"md:px-6 md:py-8",
)}
aria-label="๋กœ๊ทธ์ธ ํผ"
onSubmit={handleSubmit}
noValidate
>
{/* ์ด๋ฉ”์ผ ํ•„๋“œ */}
<div className="flex w-full max-w-[36.6rem] flex-col gap-4 mx-auto">
<div className="flex items-center justify-between">
<label htmlFor="login-email" className="t-14-m text-[var(--color-gray-700)]">
์ด๋ฉ”์ผ
</label>

{emailError && (
<span className="t-12-m text-[var(--color-red-500)]">์ด๋ฉ”์ผ ์ •๋ณด๋ฅผ ํ™•์ธํ•ด ์ฃผ์„ธ์š”.</span>
)}
</div>
<Input
id="login-email"
name="email"
type="email"
placeholder="์ด๋ฉ”์ผ์„ ์ž…๋ ฅํ•˜์„ธ์š”"
status={emailError ? "error" : "default"}
autoComplete="email"
required
value={email}
onChange={handleEmailChange}
onFocus={clearEmailError} // ๋‹ค์‹œ ํด๋ฆญํ•˜๋ฉด ์—๋Ÿฌ ํ•ด์ œ โ†’ ๊ฒ€์€ ํ…Œ๋‘๋ฆฌ
/>
</div>

{/* ๋น„๋ฐ€๋ฒˆํ˜ธ ํ•„๋“œ + ํ‘œ์‹œ ํ† ๊ธ€ */}
<div className="flex w-full max-w-[36.6rem] flex-col gap-4 mx-auto">
<div className="flex items-center justify-between">
<label htmlFor="login-password" className="t-14-m text-[var(--color-gray-700)]">
๋น„๋ฐ€๋ฒˆํ˜ธ
</label>

{passwordError && (
<span className="t-12-m text-[var(--color-red-500)]">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•ด ์ฃผ์„ธ์š”.</span>
)}
</div>
<div className="relative w-full">
<Input
id="login-password"
name="password"
type={isPasswordVisible ? "text" : "password"}
status={passwordError ? "error" : "default"}
autoComplete="current-password"
required
className="w-full pr-10"
value={password}
onChange={handlePasswordChange}
onFocus={clearPasswordError} // ๋‹ค์‹œ ํด๋ฆญํ•˜๋ฉด ์—๋Ÿฌ ํ•ด์ œ
/>
{/* ๋น„๋ฐ€๋ฒˆํ˜ธ ํ‘œ์‹œ/์ˆจ๊น€ ํ† ๊ธ€ ์•„์ด์ฝ˜ */}
<button
type="button"
className="absolute right-5 top-1/2 -translate-y-1/2 cursor-pointer"
aria-label={isPasswordVisible ? "๋น„๋ฐ€๋ฒˆํ˜ธ ์ˆจ๊ธฐ๊ธฐ" : "๋น„๋ฐ€๋ฒˆํ˜ธ ํ‘œ์‹œ"}
aria-pressed={isPasswordVisible}
onClick={togglePasswordVisible}
>
<Icon
name={isPasswordVisible ? "eyeOff" : "eye"}
size={18}
className="text-[var(--color-gray-500)]"
/>
</button>
</div>
</div>

{/* ๋กœ๊ทธ์ธ ๋ฒ„ํŠผ */}
<div className="w-full max-w-[36.6rem] mx-auto">
<Button type="submit" preset="signup" bg="basic" className="w-full">
๋กœ๊ทธ์ธ
</Button>
</div>

{/* ํ—ฌํผ ๋งํฌ: ๋น„๋ฐ€๋ฒˆํ˜ธ ์ฐพ๊ธฐ / ํšŒ์›๊ฐ€์ž… */}
<div className="flex w-full max-w-[36.6rem] flex-col gap-4 text-center mx-auto">
<p className="t-14-m text-[var(--color-gray-600)]">
๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?{" "}
<Link
href="/forgot-password"
className="t-14-m text-[var(--color-gray-900)] underline-offset-2 hover:underline"
>
๋น„๋ฐ€๋ฒˆํ˜ธ ์ฐพ๊ธฐ
</Link>
</p>
<p className="t-14-m text-[var(--color-gray-600)]">
ํšŒ์›์ด ์•„๋‹ˆ์‹ ๊ฐ€์š”?{" "}
<Link
href="/signup"
className="t-14-m text-[var(--color-gray-900)] underline-offset-2 hover:underline"
>
ํšŒ์›๊ฐ€์ž…ํ•˜๊ธฐ
</Link>
</p>
</div>

{/* ๊ฐ„ํŽธ ๋กœ๊ทธ์ธ + ์†Œ์…œ ๋ฒ„ํŠผ */}
<div className="flex w-full max-w-[36.6rem] flex-col gap-4 pt-2 mx-auto">
<div className="flex items-center gap-4 w-full">
<div className="h-px flex-1 bg-[var(--color-gray-200)]" />
<span className="t-14-m text-[var(--color-gray-500)]">๊ฐ„ํŽธ ๋กœ๊ทธ์ธ</span>
<div className="h-px flex-1 bg-[var(--color-gray-200)]" />
</div>

<div className="flex w-full flex-col items-center gap-5">
<Button type="button" preset="signup" bg="kakao" className="w-full">
<span>์นด์นด์˜คํ†ก์œผ๋กœ ๋กœ๊ทธ์ธ</span>
</Button>

<Button type="button" preset="signup" bg="google" className="w-full">
<span>๊ตฌ๊ธ€๋กœ ๋กœ๊ทธ์ธ</span>
</Button>
</div>
</div>
</form>
);
}
2 changes: 1 addition & 1 deletion src/lib/variants/button.signup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const signupButtonVariants = cva(
[
// Layout (๊ณตํ†ต)
"inline-flex items-center justify-center",
"w-[36.6rem] h-[6.2rem] px-[3rem] rounded-lg cursor-pointer",
"max-w-[36.6rem] h-[4.6rem] px-[3rem] rounded-lg cursor-pointer",

// Typography (๊ณตํ†ต)
"t-16-m",
Expand Down
10 changes: 1 addition & 9 deletions src/lib/variants/input.auth.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
// src/lib/variants/input.auth.ts
import { cva, type VariantProps } from "class-variance-authority";

/**
* ๋กœ๊ทธ์ธ ์ธํ’‹ ์ปดํฌ๋„ŒํŠธ์˜ ์Šคํƒ€์ผ variant
* - ๊ธฐ๋ณธ: 1px + gray-300
* - ํฌ์ปค์Šค: 1.5px + gray-900
* - ์—๋Ÿฌ: 1.5px + danger-600
* - ์—๋Ÿฌ ์ƒํƒœ์—์„œ ํฌ์ปค์Šค ์‹œ: ํฌ์ปค์Šค ๊ทœ์น™(gray-900)๋กœ ๋ณต๊ท€
*/
export const authInputVariants = cva(
[
// === ๊ธฐ๋ณธ ๋ ˆ์ด์•„์›ƒ ===
"w-[36.6rem] h-[4.6rem] px-6 rounded-lg bg-white t-14-m outline-none",
"max-w-[36.6rem] h-[4.6rem] px-6 rounded-lg bg-white t-14-m outline-none",

// === ํ”Œ๋ ˆ์ด์Šคํ™€๋” ===
"placeholder:text-[var(--color-gray-500)]",
Expand Down
55 changes: 55 additions & 0 deletions src/stores/authForm.store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import type { AuthFormState } from "@/types/authForm";
import { create } from "zustand";

export const useAuthFormStore = create<AuthFormState>((set, get) => ({
email: "",
password: "",
emailError: false,
passwordError: false,
isPasswordVisible: false,

setEmail: (value) => set({ email: value }),
setPassword: (value) => set({ password: value }),

clearEmailError: () => set({ emailError: false }),
clearPasswordError: () => set({ passwordError: false }),

togglePasswordVisible: () => set((state) => ({ isPasswordVisible: !state.isPasswordVisible })),

validateLogin: () => {
const { email, password } = get();

let emailError = false;
let passwordError = false;

// ์ด๋ฉ”์ผ: ๋น„์–ด ์žˆ๊ฑฐ๋‚˜ ํ˜•์‹์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์œผ๋ฉด ์—๋Ÿฌ
const trimmedEmail = email.trim();
const isValidEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(trimmedEmail);

if (!trimmedEmail || !isValidEmail) {
emailError = true;
}

// ๋น„๋ฐ€๋ฒˆํ˜ธ: 6์ž๋ฆฌ ์ด์ƒ + ํŠน์ˆ˜๋ฌธ์ž 1๊ฐœ ์ด์ƒ
const hasMinLength = password.length >= 6;
const hasSpecialChar = /[^A-Za-z0-9]/.test(password);

if (!hasMinLength || !hasSpecialChar) {
passwordError = true;
}

// ํ•˜๋‚˜๋ผ๋„ ์—๋Ÿฌ๊ฐ€ ์žˆ์œผ๋ฉด ํ•ด๋‹น ํ•„๋“œ ๊ฐ’ ์ดˆ๊ธฐํ™” + ์—๋Ÿฌ ํ”Œ๋ž˜๊ทธ ์„ธํŒ…
if (emailError || passwordError) {
set({
email: emailError ? "" : email,
password: passwordError ? "" : password,
emailError,
passwordError,
});
return false;
}

set({ emailError: false, passwordError: false });
return true;
Comment on lines +19 to +53

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Persist trimmed email after validation

The validator trims whitespace to check the email format but, in the success path, the store keeps the original email string (emailError remains false and no set occurs with the trimmed value). A user who types " [email protected] " will pass validation, yet the state still contains the leading/trailing spaces; any subsequent login request that reads email from the store will send the untrimmed value and likely be rejected serverโ€‘side despite the UI reporting success. Store the trimmed email when validation passes or fail validation if whitespace is present.

Useful? React with ๐Ÿ‘ย / ๐Ÿ‘Ž.

},
}));
17 changes: 17 additions & 0 deletions src/types/authForm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export interface AuthFormState {
email: string;
password: string;
emailError: boolean;
passwordError: boolean;
isPasswordVisible: boolean;

setEmail: (value: string) => void;
setPassword: (value: string) => void;

clearEmailError: () => void;
clearPasswordError: () => void;

togglePasswordVisible: () => void;

validateLogin: () => boolean;
}