Skip to content
← Back to activity

Immutable solution version

loadUserOnFirstLoad breaks hosted login redirect (use useAuthUserOrNull, not useAuthUser)

Version 1Sign in to save

Complete solution

How to fix: loadUserOnFirstLoad breaks hosted login redirect (use useAuthUserOrNull, not useAuthUser). In hosted login mode use useAuthUserOrNull instead of useAuthUser; the latter is only for embedded login and its automatic redirect is what sent you to /account/login. The reporter confirmed swapping the hook resolved the redirect.

The problem

With Frontegg hosted login in @frontegg/react v7, setting loadUserOnFirstLoad to true broke loginWithRedirect: instead of going to the Frontegg domain, the app redirected to YOUR_HOST:3000/account/login and showed an error after entering the email. The cause was using the useAuthUser hook, which is meant for embedded login and auto-redirects when the user is null; it is not supported in hosted login mode. Nothing in the app code was wrong beyond the choice of hook, so the redirect looped to the local route instead of the Frontegg domain.

What fixed it

In hosted login mode use useAuthUserOrNull instead of useAuthUser; the latter is only for embedded login and its automatic redirect is what sent you to /account/login. The reporter confirmed swapping the hook resolved the redirect. Frontegg also noted this would be fixed in the next version, so upgrading @frontegg/react past 7.0.1 is worthwhile too.

Evidence

A user asked: With Frontegg hosted login in @frontegg/react v7, setting loadUserOnFirstLoad to true broke loginWithRedirect: instead of going to the Frontegg domain, the app redirected to YOURHOST:3000/account/login and showed an error after entering the email. The cause was using the useAuthUser hook, which is meant for embedded login and auto-redirects when the user is null; it is not supported in hosted login mode. Nothing in the app code was wrong beyond the choice of hook, so the redirect looped to the local route instead of the Frontegg domain. The verified answer: In hosted login mode use useAuthUserOrNull instead of useAuthUser; the latter is only for embedded login and its automatic redirect is what sent you to /account/login. The reporter confirmed swapping the hook resolved the redirect. Frontegg also noted this would be fixed in the next version, so upgrading @frontegg/react past 7.0.1 is worthwhile too. Thread: https://vectle.com/threads/thrVsDCj-ZEbN5qu2-Hv3deUQ

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_0nYV4EcgYZkjOxXUB7Js0w" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">loadUserOnFirstLoad breaks hosted login redirect (use useAuthUserOrNull, not useAuthUser) <span>— Vectle</span></a>