user onboarding
Hi, what do you think is the best way to make user onboarding mandatory? I'd like users to fill out their username before they can start using the app.
3 Replies
@aris_22 You could extend the user schema to have a field for
completedOnboarding
and make it either a Non Nullable Boolean or use a Nullable Date (allows you to track when users finish onboarding), then you can just check if it is set to True (Boolean Method) or Not Null (Date Method).
For typescript safety check out the docs on inference
For setting onboarding is complete either just use your ORM directly (Like drizzle or prisma) or just hit raw SQLTypeScript | Better Auth
Better Auth TypeScript integration.
Database | Better Auth
Learn how to use a database with Better Auth.
@lonelyplanet Great, thanks. Where do you think it's best to verify this field?
One option would be to obtain the session in the middleware, but I'm not sure if this is optimal since a DB query will be performed on each request.
https://www.better-auth.com/docs/concepts/hooks
Only implement the check where needed:
- For better auth specific functions use a hook (For example a user cannot accept a org invite until onboarding is complete).
- For other actions/routes/procedures/logic etc... just do a simple check
if user not onboarded then reject else continue
Also dont know if you've done this but:
User input: false
to prevent it from updated from the client for example
-# Don't use middleware for auth checks when using Fullstack frameworks like Next.JS as you will block ALL requests and add latency and may even dupe requests, Its recommended to run all auth checks per actions/routes/procedures/logic basis. You can abstract it to a function like checkAuth()
@aris_22