Vercel Deploy Problems - Cookies not detected?

I just deployed my app to vercel and m ycookies are no longer detected? I sign in e.g. with a. magic link, i see my cookies in the application but i dont get redirected or whatever When i run it locally i do get redirected, only difference is one is deployed on vercel and the other isnt
12 Replies
eoshorizon_
eoshorizon_2mo ago
any logs in vercel?
Kaylee
KayleeOP2mo ago
these the logs
No description
eoshorizon_
eoshorizon_2mo ago
did you set env for cookies etc? can you check if there is any set-cookie in these logs?
Kaylee
KayleeOP2mo ago
those are the only logs i do have a database hook at session.create will check if that is dying
eoshorizon_
eoshorizon_2mo ago
yea also add logs, maybe to debug it further
Kaylee
KayleeOP2mo ago
I guess i wonder do i need to set up the advanced cookie config too
No description
Kaylee
KayleeOP2mo ago
On the trusted origin side do you just need the hostname? e.g. https://my-app.vercel.app/ https://my-app.vercel.app/api/auth
eoshorizon_
eoshorizon_2mo ago
https://my-app.vercel.app is enough for trustedOrigins or whatever your domain is
Kaylee
KayleeOP2mo ago
can it also support wildcards? e.g. *.vercel.app as vercel has quite a few different domains Doesnt seem to be the problem i see the full session object when i console.log it As i can see th ecookies i suppose next possible thing to look at is my middlware?
ts
export async function middleware(request: NextRequest) {
const sessionCookie = getSessionCookie(request);

if (!sessionCookie) {
return NextResponse.redirect(new URL('/login', request.url));
}

return NextResponse.next();
}
ts
export async function middleware(request: NextRequest) {
const sessionCookie = getSessionCookie(request);

if (!sessionCookie) {
return NextResponse.redirect(new URL('/login', request.url));
}

return NextResponse.next();
}
Ok so my problem is with the useSecureCookies stuff Setting it true locally causes the same issue im seeing on vercel then disabling it locally it is expected (it is enabled by default in production according to docs)
eoshorizon_
eoshorizon_2mo ago
hm weird
bekacru
bekacru2mo ago
check BETTER_AUTH_URL incase it's set to localhost on vercel as well. You don't need to manually set secure cookies. Better Auth will detect that based on the enviroment and the base url.
Kaylee
KayleeOP2mo ago
Yup that was the problem, completly forgot to check its set on auth.ts, only had it set on the client :D Thank you

Did you find this page helpful?