requireAuth()
Othent JS SDK requireAuth() function
Checks if the user is authenticated and has a valid session. If they are not, they'll be prompted to authenticate, just like connect()
does. However, this behavior depends on the autoConnect
option used when instantiating Othent:
autoConnect = "off"
: CallingrequireAuth()
will always throw an error if the user is not already authenticated.In this case, you should check
isAuthenticated
yourself, and callconnect()
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 aUnable to open a popup
error.When using
auth0Strategy = "refresh-memory"
option (default), unless the user is already authenticated on the current tab, callingrequireAuth()
will throw aUnable to open a popup
orMissing 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.
API
Example usage
Last updated