Skip to content
Open
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
13 changes: 9 additions & 4 deletions apps/manager/src/app/api/auth/login/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,18 @@ export async function POST(request: Request) {
}

const cookieStore = await cookies()
cookieStore.set("strapi-jwt", jwt, {
httpOnly: true,
const cookieOpts = {
secure: process.env.NODE_ENV === "production",
sameSite: "lax",
sameSite: "lax" as const,
path: "/",
maxAge: 60 * 60 * 24 * 7, // 7 days
})
}
cookieStore.set("strapi-jwt", jwt, { ...cookieOpts, httpOnly: true })
cookieStore.set(
"manager-user",
JSON.stringify({ username: user.username, email: user.email }),
cookieOpts,
)

return NextResponse.json({
user: { id: user.id, email: user.email, role: user.role?.name },
Expand Down
1 change: 1 addition & 0 deletions apps/manager/src/app/api/auth/logout/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import { NextResponse } from "next/server"
export async function POST() {
const cookieStore = await cookies()
cookieStore.delete("strapi-jwt")
cookieStore.delete("manager-user")
return NextResponse.json({ success: true })
}
25 changes: 23 additions & 2 deletions apps/manager/src/app/dashboard/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Metadata } from "next"
import { cookies } from "next/headers"
import { redirect } from "next/navigation"
import { DashboardNav } from "@/features/nav/dashboard-nav"
import { requireAuth } from "@/lib/require-auth"

export const metadata: Metadata = {
title: "Dashboard — VideoForge Manager",
Expand All @@ -11,7 +12,27 @@ export default async function DashboardLayout({
}: {
children: React.ReactNode
}) {
const user = await requireAuth()
const cookieStore = await cookies()
const jwt = cookieStore.get("strapi-jwt")?.value
if (!jwt) {
redirect("/login")
}

// Read display-only user info from cookie set at login.
// No Strapi call — avoids spurious logouts from transient upstream failures.
const raw = cookieStore.get("manager-user")?.value
let user = { username: "User", email: "" }
if (raw) {
try {
const parsed = JSON.parse(raw) as { username?: string; email?: string }
user = {
username: parsed.username ?? "User",
email: parsed.email ?? "",
}
} catch {
// Corrupted cookie — use defaults, don't block the page
}
}

return (
<main className="dashboard-main">
Expand Down
25 changes: 0 additions & 25 deletions apps/manager/src/lib/require-auth.ts

This file was deleted.

Loading