NodeJS SDK reference
authenticate
function is provided for use as Express middleware. It takes
the usual req, res, next
arguments and will call next()
if authentication
succeeds or next(err)
if it fails.
Upon successful authentication, the request will be augmented with a tokenInfo
property containing details about the authenticated token. req.isAuthenticated
will also be set to true
.
Each user’s information is cached in memory for a short period of time to speed
up subsequent requests.
See the Express example for a working implementation.
Here’s an example protecting one route:
authenticate()
function accepts an optional options
object containing
the following properties:
fetchUserInfo: boolean (default: false)
- If true
, the user’s data will
be fetched from the Rownd API and annotated on the request object as
req.user
. When present, it will contain a set of key/value pairs that match
your application’s schema. The user’s data will be cached for a short period
of time to speed up subsequent requests.
errOnInvalidToken: boolean (default: true)
- When true
, the an error will
be passed to next(err)
if the token fails to validate. When false
, the
token will still be validated, but next()
will be called without an error.
req.isAuthenticated
will be false
and req.tokenInfo
will be null
.
app_key
- Your Rownd application key.app_secret
- Your Rownd application secret.timeout
- The number of milliseconds to wait before timing out a request. Defaults to 10 seconds. If you’re on a slow network and see any “Request timed out” errors, try increasing this value.instance.validateToken(token: string): Promise<TTokenValidationPayload>
Authorization
header. Be sure to strip off the Bearer
portion of the header and just pass the raw token to this method.
If the validation is successful, the resulting object will look approximately like this:
instance.fetchUserInfo(opts: TFetchUserInfoOpts): Promise<TUserInfo>
instance.createOrUpdateUser(user: TUser): Promise<void>
id
property. If the user already exists, the existing profile will be updated. If the user does not exist, a new user/profile will be created.
Example:
instance.deleteUser(userId: String): Promise<void>
instance.createSignInLink(opts: CreateSignInLinkOpts): Promise<string>