Replies: 5 comments 8 replies
-
Related https://x.com/sebastienlorber/status/1765405011826098670?s=46&t=30xnDcG7zsVn_XhbNW0vlg |
Beta Was this translation helpful? Give feedback.
-
I would personally avoid using middleware for protecting resources at all. For Next.js specifically, there still isn't a straightforward way to share data between middleware and pages. Even if the framework provided something similar to |
Beta Was this translation helpful? Give feedback.
-
Did you manage to get Lucia working in your Planetscale + Prisma Edge project? I'm currently trying the same and I'm getting an error at the validateSession part ✘ [ERROR] Session validation error: PrismaClientUnknownRequestError: Invalid Cannot select both '$scalars: true' and a specific scalar field 'session'. |
Beta Was this translation helpful? Give feedback.
-
@pilcrowonpaper there's also the problem of session expiration. You can't set cookies in pages. You need to rely on users using server actions or routes to update the session, but you might have an app that relies almost entirely on reads that come from pages. What are your thoughts on this? |
Beta Was this translation helpful? Give feedback.
-
According to the following discussion, in next.js the layout can be skipped and therefore may not be appropriate for security checks (depending on exactly what you are trying to achieve) https://www.reddit.com/r/nextjs/comments/18yl440/using_middleware_vs_auth_checks_on_every_page/ |
Beta Was this translation helpful? Give feedback.
-
Hi @pilcrowonpaper Thanks for this amazing library <3
I found your following reply regarding the middleware.ts vs protected layout.ts debate on Reddit: https://www.reddit.com/r/nextjs/comments/18q7gyq/comment/keujdn0/
In the case of Prisma: There are efforts under way to make Prisma compatible with the Edge Runtime. In another project of mine, I already use a beta release of Prisma which works with PlanetScale in Vercel's Edge Runtime.
So in this scenario, where the ORM provides Edge Support (so that it works in the middleware.ts) and the serverless DB (or ORM) provides world wide read replicas (like PlanetScale or Prisma Accelerate), would you say that it would be better to put the route protection on the middleware level or would it still be okay to use it in a layout.ts file in Next?
Is there any difference at all (or from a security perspective)?
Thanks for your time and effort. Maybe someone else can answer this question as well :)
Beta Was this translation helpful? Give feedback.
All reactions