feat: 로그인 화면 및 공통 속성 생성

This commit is contained in:
2025-12-31 18:40:46 +09:00
parent 822cd55c93
commit 7400363466
17 changed files with 689 additions and 17 deletions

31
src/store/auth.tsx Normal file
View File

@@ -0,0 +1,31 @@
import React, { createContext, useContext, useMemo, useState } from "react";
export type AuthContextValue = {
isAuthed: boolean;
login: () => void;
logout: () => void;
};
const AuthContext = createContext<AuthContextValue | null>(null);
export function AuthProvider({ children }: { children: React.ReactNode }) {
const [isAuthed, setIsAuthed] = useState<boolean>(false);
console.log("isAuthed: " + isAuthed);
const value = useMemo<AuthContextValue>(
() => ({
isAuthed,
login: () => setIsAuthed(true),
logout: () => setIsAuthed(false),
}),
[isAuthed]
);
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
}
export function useAuth(): AuthContextValue {
const ctx = useContext(AuthContext);
if (!ctx) throw new Error("useAuth must be used within AuthProvider");
return ctx;
}