requireAuth()
Othent JS SDK requireAuth() function
Last updated
Othent JS SDK requireAuth() function
Last updated
Checks if the user is authenticated and has a valid session. If they are not, they'll be prompted to authenticate, just like does. However, this behavior depends on the autoConnect
option used when instantiating Othent:
autoConnect = "off"
: Calling requireAuth()
will always throw an error if the user is not already authenticated.
In this case, you should check yourself, and call if the user is not authenticated, before attempting to perform any operation with Othent.
autoConnect = "lazy"
: Authenticates them automatically, either from an existing session or by prompting them to sign in/up again. It throws an error if authentication fails.
autoConnect = "eager"
: Validates the user session or prompts the user to sign in/up again as soon as you instantiate Othent.
If the user is not authenticated, calling requireAuth()
before the user interacts with the page (e.g. by clicking on a button), will throw a Unable to open a popup
error.
When using auth0Strategy = "refresh-memory"
option (default), unless the user is already authenticated on the current tab, calling requireAuth()
will throw a Unable to open a popup
or Missing Refresh Token
error.
All other functions (except the getters) call this function automatically to ensure they can perform the operation they are supposed to, so unless you instantiated Othent with autoConnect = "off"
, you don't need to use it.