fix: check for __Secure- prefixed session cookie in middleware
better-auth uses __Secure- prefix for session cookies on HTTPS, but middleware was only checking for the unprefixed cookie name 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
499f163c31
commit
87a9517ec3
1 changed files with 4 additions and 1 deletions
|
|
@ -4,7 +4,10 @@ import type { NextRequest } from 'next/server';
|
|||
export function middleware(request: NextRequest) {
|
||||
// Protect /dashboard routes
|
||||
if (request.nextUrl.pathname.startsWith('/dashboard')) {
|
||||
const sessionToken = request.cookies.get('better-auth.session_token');
|
||||
// Check for session token - better-auth uses __Secure- prefix for HTTPS cookies
|
||||
const sessionToken =
|
||||
request.cookies.get('__Secure-better-auth.session_token') ||
|
||||
request.cookies.get('better-auth.session_token');
|
||||
if (!sessionToken) {
|
||||
return NextResponse.redirect(new URL('/sign-in', request.url));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue