refactor: consolidate protected routes under /intern/*

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
mikl0s 2026-02-22 21:53:20 +00:00
parent 90407c4f8d
commit efe19f0cda
5 changed files with 12 additions and 20 deletions

View file

@ -40,7 +40,7 @@ export default function HistorikPage() {
const res = await fetch("/api/quotes")
if (!res.ok) {
if (res.status === 401) {
router.push("/login")
router.push("/intern/login")
return
}
throw new Error("Failed to fetch quotes")
@ -57,7 +57,7 @@ export default function HistorikPage() {
async function handleLogout() {
try {
await fetch("/api/auth/logout", { method: "POST" })
router.push("/login")
router.push("/intern/login")
router.refresh()
} catch (error) {
console.error("Logout failed:", error)
@ -104,7 +104,7 @@ export default function HistorikPage() {
</div>
<div className="flex items-center gap-2">
<Link href="/dashboard">
<Link href="/intern">
<Button variant="ghost" size="sm">
<LayoutDashboard className="mr-2 h-4 w-4" />
<span className="hidden sm:inline">Dashboard</span>

View file

@ -35,7 +35,7 @@ export default function LoginPage() {
return
}
router.push("/dashboard")
router.push("/intern")
router.refresh()
} catch {
setError("Der opstod en fejl. Prøv igen.")

View file

@ -38,7 +38,7 @@ export default function DashboardPage() {
const res = await fetch("/api/quotes")
if (!res.ok) {
if (res.status === 401) {
router.push("/login")
router.push("/intern/login")
return
}
throw new Error("Failed to fetch quotes")
@ -84,7 +84,7 @@ export default function DashboardPage() {
async function handleLogout() {
try {
await fetch("/api/auth/logout", { method: "POST" })
router.push("/login")
router.push("/intern/login")
router.refresh()
} catch (error) {
console.error("Logout failed:", error)
@ -133,7 +133,7 @@ export default function DashboardPage() {
</div>
<div className="flex items-center gap-2">
<Link href="/historik">
<Link href="/intern/historik">
<Button variant="ghost" size="sm">
<List className="mr-2 h-4 w-4" />
<span className="hidden sm:inline">Historik</span>

View file

@ -1,34 +1,26 @@
import { NextResponse } from "next/server"
import type { NextRequest } from "next/server"
// Routes that require authentication
const protectedPaths = ["/dashboard", "/historik", "/admin"]
export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl
// Check if path requires authentication
const isProtectedPath = protectedPaths.some((path) => pathname.startsWith(path))
if (!isProtectedPath) {
// Don't protect the login page
if (pathname === "/intern/login") {
return NextResponse.next()
}
// Check for session cookie
// Check for session cookie on all /intern/* routes
const sessionCookie = request.cookies.get("session")
if (!sessionCookie?.value) {
// Redirect to login
const loginUrl = new URL("/login", request.url)
const loginUrl = new URL("/intern/login", request.url)
loginUrl.searchParams.set("redirect", pathname)
return NextResponse.redirect(loginUrl)
}
// Cookie exists - let the page validate the session
// (Session validation happens server-side in the page)
return NextResponse.next()
}
export const config = {
matcher: ["/dashboard/:path*", "/historik/:path*", "/admin/:path*"],
matcher: ["/intern/:path*"],
}