onboarding wizard: handle custom fields on session and caching session
hi. i'm a new nextjs dev and interested in using better auth in this project. im currently have trouble understanding and finding solution about session. here is what i want to achieve:
- when the app is freshly build, there will be a default superadmin account (i implement my own role management, not using the admin or organization plugin)
- when superadmin login, user need to do a first setup wizard. and when this setup is not completed, we cant access any route until setup is completed
problem:
- i am confused how should i enforce the first setup wizard. i store a flag in database, isSetupCompleted to determine if setup is completed or not.
- i plan to make the check in middleware (because middleware will run this on protected route and api route). here i dont really want to call database everytime, so my idea is to store the flag in the session using custom session plugin.
- i read in the docs, this custom session is not including in caching
- i read in this forum: https://www.answeroverflow.com/m/1364575017102479450 . here mentioned that we can cache the customefield ourself.
questions:
- can we do the caching in the middleware? if yes, how?
- is my method of using middleware to check then enforcing first setup bad? is there a better way to handle this?
notes:
i have other idea how to handle this:
- calling database in the middleware for the flag
- store it in a variable inside the middleware, with check interval timer
- if isSetupCompleted = true, the middleware will simply let the request through, no db call needed
- if isSetupCompleted = false, and last checked exceed the check interval, i will revalidate the flag by calling the database again, if its still false, set it in flag variable, then enforce setup, if it become true, set it in flag variable, then let the request through
please help me and give your opinion, thank you
Session Caching with Custom Fields Workaround - Better Auth
I've been using Next Auth and was thinking to switch over, however the line below is making me hesitate. I do not want to hit the db on every request, but I also want to use custom fields such as roles. Is there an alternative or work around for this?
```
Session caching, including secondary storage or cookie cache, does not include custom fiel...
0 Replies