lucia-auth / examples

A collection of example projects built with Lucia
MIT License
214 stars 52 forks source link

In NextJS App Router, cookies should not be set in server components #47

Closed jacobtipp closed 2 weeks ago

jacobtipp commented 3 weeks ago

In the nextjs app router examples, I noticed that you are setting the session cookie inside the validateRequest method. validateRequest is then used in server components to check for the user session. Normally nextjs would throw an error but you seem to be swallowing it with the try catch block. What are the implications of this?

samcxps commented 2 weeks ago

Bump!

Came to the Issues looking for this exact answer. Is it just so validateRequest can also be used in route handlers, server actions, and server components without having to have separate functions for each?

TYIA

pilcrowOnPaper commented 2 weeks ago

Yeah it's just easier to swallow the error and make validateRequest() available everywhere. We set expires: false which sets the cookie (not the session itself) expiration to a year instead of the default 30 days (or however long you set the session expiration to)