Installation
@niledatabase/client
exposes the the client side functions for various authorization requests. It handles API requests for sign-in, sign-up, sessions, and password reset. The client is designed to work with @niledatabase/server
which provides the server-side routes.
Getting Started
For most cases, These helpers call the underlying singleton instance ofAuthorizer
, which can be accessed via auth
getSession
Fetches the current session. If a session is cached and still valid it returns that, otherwise it requests/auth/session
.
signIn
Sends a sign-in request to the authentication endpoint. The initial signIn values are the supported providers for single sign on, in addition tocredentials
Params
Name | Type | Description |
---|---|---|
callbackUrl | string | The URL to return when the request is complete. |
redirect | boolean | Allows configuration of client-side redirects in the case of credential login |
signOut
Logs the user out and clears the session.signUp
Creates a new user account. You can also create tenants during sign up. A boolean value will create a tenant with the same email address. If a string is passed, that will be the name of the created tenant.resetPassword
Sends requests to the password reset endpoints. You must be an authorized user to do this action.getCsrfToken
Returns a CSRF token used for form submissions.getProviders
Returns a list of available authentication providers.Authorizer
You can also customize your own authorizer on the client by creating an instance ofAuthorizer
.
Constructor Options
new Authorizer(config)
accepts the following options:
Name | Type | Description |
---|---|---|
baseUrl | string | The base URL of your application. |
basePath | string | Optional API path, defaults to /api . |
init | RequestInit | Default fetch options for all requests. |
state
object with baseUrl
, session
, and loading status. You can update the configuration later by calling auth.configure({ baseUrl })
.