getSessionCookie() is not behaving like we expect for the next reasons:auth.ts https:// cookies will be secured by default if you don't specify the useSecureCookies option.__secure- in production ignoring the code above request.nextUrl.origin.startsWith("https://" to add the secure prefix.