Integrate Nile Auth with express applications
Install packages
Configure the extension
handlers[method]
and paths[method]
to be compatible with express.AsyncLocalStorage
and middleware to ensure each request has the correct context./api/auth/signin
, /api/tenants/:tenantId/users
, etc). This allows you to override specific routes, or add new ones since nile only matches specific routes (either the default, or ones that have been configured)
Additionally, since the base @niledatabase/server
assumes standard Request
and Response
objects, this extension turns express objects into those and responds accordingly.
Lastly, because of the express lifecycle, its important to be sure that each requests is executed within a specific context. We automatically add a :tenantId
param listener and set the context of the nile instance to that tenantId for convenience. That way, no matter the request or DB query, if you have the tenantId in your param (this also works automatically with the nile.tenantId
cookie), there’s no additional work that needs done.