Skip to content

Commit 9007d98

Browse files
refactor middleware logic for prod env
1 parent 4eeebe8 commit 9007d98

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/app/layout.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { type Metadata } from "next";
66
import { TRPCReactProvider } from "@/trpc/react";
77
import { AuthProvider } from "@/components/AuthProvider";
88
import { Toaster } from "@/components/ui/sonner";
9-
import { ThemeProvider } from "@/components/ThemeProvider";
109

1110
export const metadata: Metadata = {
1211
title: "WorkNest",
@@ -22,7 +21,6 @@ export default function RootLayout({
2221
<body>
2322
<AuthProvider>
2423
<TRPCReactProvider>
25-
<ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
2624
{children}
2725
<Toaster
2826
toastOptions={{
@@ -31,7 +29,6 @@ export default function RootLayout({
3129
},
3230
}}
3331
/>
34-
</ThemeProvider>
3532
</TRPCReactProvider>
3633
</AuthProvider>
3734
</body>

src/middleware.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ import { NextResponse, type NextRequest } from "next/server";
22
import { getToken } from "next-auth/jwt";
33

44
export async function middleware(req: NextRequest) {
5-
const token = await getToken({ req, secret: process.env.AUTH_SECRET! });
6-
const isAuthenticated = !!token;
5+
const token = await getToken({
6+
req,
7+
secret: process.env.AUTH_SECRET!,
8+
cookieName: "next-auth.session-token",
9+
});
710

11+
const isAuthenticated = !!token;
812
const path = req.nextUrl.pathname;
13+
914
const publicPaths = ["/", "/organizing-projects-animate.svg", "/feedback-animate.svg"]; // including svgs
1015
const isPublicPath = publicPaths.includes(path) || path.startsWith("/api/");
1116

src/server/auth/config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,16 @@ export const authConfig = {
5858
},
5959
}),
6060
},
61+
cookies: {
62+
sessionToken: {
63+
name: "next-auth.session-token",
64+
options: {
65+
httpOnly: true,
66+
sameSite: "lax",
67+
path: "/",
68+
secure: true,
69+
domain: ".cloudfront.net",
70+
}
71+
}
72+
},
6173
} satisfies NextAuthConfig;

0 commit comments

Comments
 (0)