How to handle deleted user?

I have a next app set up with auth using better-auth. I'm using basic middleware like this
import { getSessionCookie } from "better-auth/cookies";
export async function middleware(request: NextRequest) {
const session = getSessionCookie(request);
if (!session && isProtectedRoute) {
return NextResponse.redirect(new URL("/login", request.url));
}
return NextResponse.next();
}
import { getSessionCookie } from "better-auth/cookies";
export async function middleware(request: NextRequest) {
const session = getSessionCookie(request);
if (!session && isProtectedRoute) {
return NextResponse.redirect(new URL("/login", request.url));
}
return NextResponse.next();
}
Everything was running normally until I tested what would happen if I deleted a user manually from the database, including their session and then I did delete a user. After that, the app threw this error Error: Missing <html> and <body> tags in the root layout. Read more at There is still better-auth.session_token in the cookie tho, so it seems like the middleware doesn't do its job properly, but I'm clueless why it doesn't check the cookie or invalidate the cookie. What am I missing here?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?