Skip to content

Commit c6b0cf1

Browse files
authored
feat: 로그인 상태 유지 및 홈 접근 리다이렉트 처리
* feat: 로그인 상태 유지 및 홈 전근 처리 * feat: 로그인 상태 유지 및 홈 접근 리다이렉트 처리
1 parent 0a524f9 commit c6b0cf1

4 files changed

Lines changed: 38 additions & 5 deletions

File tree

src/app/App.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BrowserRouter, Routes, Route } from "react-router";
1+
import { BrowserRouter, Navigate, Routes, Route } from "react-router";
22
import { ThemeProvider } from "./contexts/ThemeContext";
33
import { LanguageProvider } from "./contexts/LanguageContext";
44
import { Layout } from "./components/Layout";
@@ -19,6 +19,11 @@ import { LoginPage } from "./pages/LoginPage";
1919
import { SignupPage } from "./pages/SignupPage";
2020
import { ProfilePage } from "./pages/ProfilePage";
2121
import { SettingsPage } from "./pages/SettingsPage";
22+
import { isAuthenticated } from "./auth";
23+
24+
function HomeRoute() {
25+
return isAuthenticated() ? <Navigate to="/workspace" replace /> : <HomePage />;
26+
}
2227

2328
export default function App() {
2429
return (
@@ -28,7 +33,7 @@ export default function App() {
2833
<LanguageDomSync />
2934
<Routes>
3035
<Route element={<PublicLayout />}>
31-
<Route path="/" element={<HomePage />} />
36+
<Route path="/" element={<HomeRoute />} />
3237
</Route>
3338
<Route element={<AuthLayout />}>
3439
<Route path="/login" element={<LoginPage />} />

src/app/auth.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const AUTH_SESSION_KEY = "codedock-authenticated";
2+
3+
export function isAuthenticated() {
4+
if (typeof window === "undefined" || typeof window.localStorage === "undefined") {
5+
return false;
6+
}
7+
8+
return window.localStorage.getItem(AUTH_SESSION_KEY) === "true";
9+
}
10+
11+
export function setAuthenticated() {
12+
if (typeof window === "undefined" || typeof window.localStorage === "undefined") {
13+
return;
14+
}
15+
16+
window.localStorage.setItem(AUTH_SESSION_KEY, "true");
17+
}
18+
19+
export function clearAuthenticated() {
20+
if (typeof window === "undefined" || typeof window.localStorage === "undefined") {
21+
return;
22+
}
23+
24+
window.localStorage.removeItem(AUTH_SESSION_KEY);
25+
}

src/app/components/Layout.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
DropdownMenuTrigger,
1717
} from "./ui/dropdown-menu";
1818
import { useTheme } from "../contexts/ThemeContext";
19+
import { clearAuthenticated } from "../auth";
1920

2021
const navItems = [
2122
{ path: "/workspace", label: "Dashboard" },
@@ -38,6 +39,7 @@ export function Layout() {
3839

3940
const isActive = (path: string) => location.pathname === path;
4041
const handleLogout = () => {
42+
clearAuthenticated();
4143
navigate("/login");
4244
};
4345

@@ -90,7 +92,7 @@ export function Layout() {
9092
>
9193
<div className="relative mx-auto flex w-[min(1400px,100%)] items-center justify-between gap-4">
9294
<Link
93-
to="/"
95+
to="/workspace"
9496
className="codedock-brand-link flex items-center gap-3 no-underline transition-all duration-300"
9597
style={{
9698
color: "var(--white)",

src/app/pages/LoginPage.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { CodeDockWordmark } from "../components/CodeDockWordmark";
1818
import { CoffeeLogo } from "../components/CoffeeLogo";
1919
import { useLanguage } from "../contexts/LanguageContext";
2020
import { useTheme } from "../contexts/ThemeContext";
21+
import { setAuthenticated } from "../auth";
2122

2223
const loginDemoMessagesKo = [
2324
{ speaker: "CodeDock", text: "위험 파일 3개를 먼저 묶었어요.", tone: "#B7FFE3" },
@@ -189,12 +190,12 @@ export function LoginPage() {
189190

190191
const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
191192
event.preventDefault();
192-
console.log("Login:", { email, password, rememberMe });
193+
setAuthenticated();
193194
navigate("/workspace");
194195
};
195196

196197
const handleGithubLogin = () => {
197-
console.log("GitHub Login");
198+
setAuthenticated();
198199
navigate("/workspace");
199200
};
200201

0 commit comments

Comments
 (0)