Authentication
How Cascade handles authentication and authorization.
Next Auth
Cascade is based on T3 app meaning that it uses NextAuth.js under the hood. Docs are here.
This documentation is a brief overview of what is put on top of NextAuth.js to make it work with Cascade. We will focus on interesting parts!
We extend the Session
object with some additional types to make it work with Cascade. We need to add role
and planId
to the user object.
In callbacks we need to fetch the user from the database and add the role
and planId
to the session object. This is done to make sure that whenever you are working with Session from NextAuth.js you have all the necessary information about the user.
External services
Next Auth is a great entrypoint for other services we need to use for our SaaS.
For example, here we use events to manage the following:
- Sentry - to connect user to the Sentry error tracking, so we could easily debug it.
- Trigger.dev - to trigger a background job to send a notification when a new user signs up
- Loops - to send a welcome email to the new users.
Providers
Cascade comes with Discord & Google providers out of the box. You can easily add more providers by following the NextAuth.js documentation.