Next.js Discord

Discord Forum

Creating a DAL

Unanswered
Hooded Warbler posted this in #help-forum
Open in Discord
Hooded WarblerOP
Hey hope everyone is having a great day. I'm trying to setup an authentication flow. And for that I found this github post: https://github.com/vercel/next.js/discussions/63775 (I'm also adding as an image the intended flow of requests placed on the post). I read a lot of documentation regarding this from the NextJS documentation, but I'm not sure if my current flow is correct or intended. From my understanding, the DAL described abstracts the user session state/permissions to just render (send to the client) the data authorized for that specific user which makes sense. The data/user session also must be stored on cookies on the server side (Because my lack of knowledge on how the next cookies work I have a question: will that send the jwt token (stored on the cookie) to the client? Or it will keep the cookie on the server with kind of a sticky session so the server knows the device for the user and therefore always know the session cookie for that device) . Based on this to achieve this I understand I need the following:

- The data fetching and mutations must be server actions. Those server actions must have a direct communication with the access layer functions in order to get the correct permissions for the user (basically another function or abstraction also on the server which gets the cookies() from next/header and makes the desired functionality based on user permissions for example).
- An auth provider that could be custom or managed by a third-party that gives me a token to store it on the cookies.
- Because the fetch of the data is going to be server side client components just need to use that data passed by the server actions/components.

In that regard I have an extra question. In the past I managed global state using redux (specifically for persistency). I understand that with all of this server side functionality that changes by a lot. Is redux and global stores a thing using nextjs? Or server actions and caching/memoizing things are enough?

0 Replies