Skip to content

Commit fd99201

Browse files
committed
feat(auth): 프론트 로그인 검증
1 parent d80157b commit fd99201

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

front/src/app/(dashboard)/analysis/loading/page.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
"use client"
33

44
import LoadingContent from "@/components/analysis/LoadingContent"
5+
import { useRequireAuth } from "@/hooks/auth/useRequireAuth"
56

67
export default function LoadingPage() {
8+
const { user } = useRequireAuth()
9+
if (!user) return null
10+
711
return <LoadingContent />
812
}

front/src/app/(dashboard)/analysis/page.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@
33
"use client"
44

55
import type React from "react"
6-
import { useState } from "react"
6+
import { useState, useEffect } from "react"
77
import { useRouter } from "next/navigation"
88
import { Button } from "@/components/ui/Button"
99
import { Input } from "@/components/ui/input"
1010
import { Label } from "@/components/ui/label"
1111
import { Card } from "@/components/ui/card"
1212
import { Sparkles, Github, Clock, TrendingUp, Search } from "lucide-react"
13-
import { analysisApi } from "@/lib/api/analysis"
1413
import { isValidGitHubUrl } from "@/lib/utils/validation"
1514
import { useAnalysis } from "@/hooks/analysis/useAnalysis"
15+
import { useRequireAuth } from "@/hooks/auth/useRequireAuth"
1616

1717
export default function AnalyzePage() {
1818
const [repoUrl, setRepoUrl] = useState("")
1919
const [isValidUrl, setIsValidUrl] = useState(true)
2020
const router = useRouter()
2121
const { requestAnalysis, isLoading, error } = useAnalysis()
2222

23+
const { user } = useRequireAuth()
24+
if (!user) return null
25+
2326
const handleSubmit = (e: React.FormEvent) => {
2427
e.preventDefault();
2528

front/src/app/page.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,16 @@ export default function LandingPage() {
1111

1212
const handleStartAnalysis = () => {
1313
if (!isAuthed && !user) {
14-
alert("분석 시작하기는 아직 개발중!")
14+
router.push(`/login`)
1515
return
1616
}
17-
router.push("/analysis")
17+
router.push(`/analysis`)
1818
}
1919

2020
const handleGoCommunity = () => {
21-
if (!isAuthed && !user) {
22-
alert("커뮤니티는 아직 개발중!")
23-
return
24-
}
25-
router.push("/community")
21+
router.push(`/community`)
2622
}
23+
2724
return (
2825
<div className="min-h-screen bg-background">
2926
{/* Hero Section */}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// hooks/useRequireAuth.ts
2+
"use client"
3+
import { useEffect } from "react"
4+
import { useRouter } from "next/navigation"
5+
import { useAuth } from "@/hooks/auth/useAuth"
6+
7+
export function useRequireAuth() {
8+
const router = useRouter()
9+
const { isAuthed, user } = useAuth()
10+
11+
useEffect(() => {
12+
if (!isAuthed || !user) {
13+
router.replace("/login")
14+
}
15+
}, [isAuthed, user, router])
16+
17+
return { user, isAuthed }
18+
}

0 commit comments

Comments
 (0)