-
Notifications
You must be signed in to change notification settings - Fork 141
Middlewares
Thomas Lynch edited this page Oct 2, 2024
·
5 revisions
-
useSession- Initialise session from cookie -
useJWT- Initialise session from jwt -
fetchSession- Fetch the account from the database based on the session identifier -
checkSession- Check that the users is logged in i.e the previous fetchSession returned a user -
onboardedMiddleware- Check if the user set their role and/or default model credentials -
csrfMiddleware- Makesreq.csrfToken()available to put in pages/json responses for GETs, or checks the_csrfbody validity for POST/PUT/DELETE/etc -
setPermissions- Set res.locals.permissions based on the current org/team context -
hasPerms- Check if a single, or multiple (or/any) permissions are true -
checkSubscriptionPlan- Check for a specific subscription plan -
checkSubscriptionBoolean- Check if the subscription plan has a boolean set to true e.g.dataConnectionsinPricingMatrix -
checkSubscriptionLimit- Check if a number usage e.g.users(number of team members) is below the limit inPricingMatrix -
checkResourceSlug- Check if the :resourceSlug param (team id) is valid for the current user and setmatchingTeamandmatchingOrglocals -
checkResourceSlug- Same thing but checks a query string -
setDefaultOrgAndTeam- SetmatchingTeamandmatchingOrglocals based on thecurrentTeamfrom the session account.
Note: all of these are keys under res.locals e.g. account -> res.locals.account.
-
account- The authed users account with some fields projected away set byfetchSession -
stripe- Thestripeproperty from the account of the org owner in the current context, or the current account if not a route that has a team/org context set bycheckSubscription -
data- Temporary data that is passed to the page props bygetServerSidePropsin SSR'd pages, set in the controllers -
limits- Limits based on the current subscription and team/org context set bycheckSubscription -
matchingTeam- Team of the current request context (note:_idprop is renamed toid) set bycheckResourceSlugand similar -
matchingOrg- Org of the current request context (note:_idprop is renamed toid) set bycheckResourceSlugand similar -
permissions- Permissions of the user in the current request context, set bysetPermissions