Frontegg Hosted Login is aligned with OpenID Connect protocol and it is how Frontegg's hosted login authenticates the user. Most frequently, the desired behavior is to redirect a non-authenticated user to the login page to complete authentication via loginWithRedirect()
method on the Frontegg client-side SDKs which is suggested in our guides.
If your application logic is different and you'd want to check whether the user is authenticated, but if they're not you wouldn't necessarily want to redirect them to the login screen, see the instructions below for such an implementation:
You should be able to pass to the
FronteggProvider
:authOptions:{ hostedLoginOptions: { loadUserOnFirstLoad: true } }
And then just check whether the user
isAuthenticated
const { user, isAuthenticated } = useAuth(); return (isAuthenticated? user?.name : user is not authenticated)
Note that loadUserOnFirstLoad
is supported with Frontegg embedded login from the below versions:
@frontegg/react@5.0.48
@frontegg/angular@5.38
@frontegg/js@6.136
@frontegg/vue@2.0.43