Abstract
unologin instance
Protected
authExecuted when encountering an authentication error.
req
res
error
void
Readonly
clientunologin instance
Protected
loginProtected
getInternal
Result of getUserTokenOptional may be stored in with the response object.
This function acts as a helper to retrieve the cached value.
This function is meant to be used in conjunction with Express-like frameworks
where one middleware function is called after another,
passing values using res.locals
.
parsed user token cached in res.locals
res
Returns a UserHandle from the current request.
Returns null
if the request contains no login information.
IMPORTANT:
This function is synchronous and the UserHandle can therefore not be trusted to be authenticated.
The returned UserHandle can however be used in any API call that accepts a UserHandle as a parameter.
In this case, the authentication happens on the unologin API.
Use getUserTokenOptional for optional authentication. Use getUserToken for required authentication.
UserHandle | null
req
res
Authenticates the user and returns a Promise to the UserToken.
Requires the user to be logged in.
The resolved UserToken is authenticated and can be trusted.
getUserTokenOptional for optional authentication.
APIError 403 unauthorized if not logged in.
APIError 403 unauthorized if login token invalid.
Promise
req
res
Authenticates the user and returns a Promise to the UserToken.
Does not require the user to be logged in. Does nothing if no login cookie is present and returns null.
The resolved UserToken is authenticated and can be trusted if not null.
Requires a cookie parser.
getUserToken for required authentication.
Promise
req
res
Decide what to do on auth error.
void
Express handler
Add a callback that is called after the login event has finished but before the response is sent to the client.
The UserToken passed to handler
is authenticated an can be trusted.
void
(req, res, userToken) => unknown
Protected
resetProtected
setProtected
Abstract
setProtected
setInternal
Set the login cookies for a response.
void
req
rest
cookie to set
cookie options
Generated using TypeDoc
Low-level HTTP request handlers and utility functions that can be used by Express, Next, or other server frameworks.