Authenticates the current connection with a JWT token.
Arguments
| Argument | Description |
|---|---|
token
| The JWT authentication token. |
Example usage
Note: the following example uses the ureq crate with the json feature to first send a request to the database's /signup endpoint which returns a token. The reqwest crate and others can be used here instead.
Alternatively, you could use a command like the following, copy the returned token, and paste it into the .authenticate() method.
As the DEFINE ACCESS statement below shows, a token will remain valid by default for 15 minutes.
Refreshing a session (.refresh())
When the server issues a token that includes a refresh component, you can obtain a new access token without signing in again. Build the usual db.authenticate(token) future, then call .refresh(). The inner future runs the refresh command and returns a new Token. If the token has no refresh material, the SDK returns an error (Missing refresh token).
This pairs with the access and refresh model configured via DEFINE ACCESS (token duration, refresh behaviour, and scope depend on your statement).