Components
useAuthenticate()
The useAuthenticate()
hook automatically redirects unauthenticated users to the sign-in page. If the user is already authenticated, this hook does nothing and allows the user to view the content normally.
This is a hook alternative to the <RedirectToSignIn />
component, useful for redirecting users programmatically.
Usage
Options
The hook accepts an options object with the following properties:
authView
: The authentication view to redirect to. Can be either "signIn" or "signUp".enabled
: Whether the authentication check is enabled. When set tofalse
, no redirection will occur.
Example with Options
Disabling the Redirect
You can conditionally disable the redirection with the enabled
option: