Extend the SDK to automatically set context in your application
@niledatabase/server
package to integrate into developer applications easier.
It allows developers to hook into the life cycle of the SDK, from REST calls to db queries and set the context according to whatever method is being used to store user session information beyond cookies.
@niledatabase/server
contains three basic items that are controlled via context:
headers
tenantId
userId
Each of these can be set and will cause the SDK to use them either as a REST call or in a database query.
nile-auth
.
More often than not, a framework-specific extension will handle setting headers
automatically when it comes to serving REST request to the client.
withContext
is called, including internally by the SDK. Use this function set the tenantId
, userId
or headers
fetch
to nile-auth
. the internal Request
object and ctx
methods are provided to the function.
fetch
completes. The raw Response
object and ctx
are provided to the function.
nile-auth
. This function is provided the params
from the calling framework. Useful for turning whatever framework’s REST handlers into a standard Request
object to be sent to nile-auth
and then calling nile-auth
directly from the extension.
Must return ExtensionState.onHandleRequest
from the function to stop the standard handlers from being called.
withContext
, allows overriding of a user id within the context.
withContext
, allows overriding of a tenant id within the context.
defineEventHandler
that the sdk does not have, as the standard signature is const { GET, POST, PUT, DELETE } = nile.handlers