diff --git a/shared-helpers/src/auth/UseRequireLoggedInUser.ts b/shared-helpers/src/auth/UseRequireLoggedInUser.ts index 835e959813..2bde9d1628 100644 --- a/shared-helpers/src/auth/UseRequireLoggedInUser.ts +++ b/shared-helpers/src/auth/UseRequireLoggedInUser.ts @@ -6,11 +6,11 @@ import { NavigationContext } from "@bloom-housing/ui-components" * Require a logged in user. Waits on initial load, then initiates a redirect to `redirectPath` if user is not * logged in. */ -function useRequireLoggedInUser(redirectPath: string) { +function useRequireLoggedInUser(redirectPath: string, disable?: boolean) { const { profile, initialStateLoaded } = useContext(AuthContext) const { router } = useContext(NavigationContext) - if (initialStateLoaded && !profile) { + if (!disable && initialStateLoaded && !profile) { void router.push(redirectPath) } return profile diff --git a/sites/public/src/lib/hooks.ts b/sites/public/src/lib/hooks.ts index 5c67f68dca..b83be94a2b 100644 --- a/sites/public/src/lib/hooks.ts +++ b/sites/public/src/lib/hooks.ts @@ -15,6 +15,7 @@ import { import { ParsedUrlQuery } from "querystring" import { AppSubmissionContext } from "./applications/AppSubmissionContext" import { getListingApplicationStatus } from "./helpers" +import { useRequireLoggedInUser } from "@bloom-housing/shared-helpers" export const useRedirectToPrevPage = (defaultPath = "/") => { const router = useRouter() @@ -32,6 +33,7 @@ export const useRedirectToPrevPage = (defaultPath = "/") => { } export const useFormConductor = (stepName: string) => { + useRequireLoggedInUser("/", !process.env.showMandatedAccounts) const context = useContext(AppSubmissionContext) const conductor = context.conductor diff --git a/sites/public/src/pages/applications/start/choose-language.tsx b/sites/public/src/pages/applications/start/choose-language.tsx index dc229176e9..a91aa8e3e8 100644 --- a/sites/public/src/pages/applications/start/choose-language.tsx +++ b/sites/public/src/pages/applications/start/choose-language.tsx @@ -57,12 +57,11 @@ const ApplicationChooseLanguage = () => { useEffect(() => { conductor.reset() if (!router.isReady && !listingId) return - if (router.isReady && !listingId) { - return process.env.showMandatedAccounts && initialStateLoaded && profile - ? undefined - : void router.push("/") + if (router.isReady) { + if (!listingId || (process.env.showMandatedAccounts && initialStateLoaded && !profile)) { + void router.push("/") + } } - if (!context.listing || context.listing.id !== listingId) { void loadListing(listingId, setListing, conductor, context, "en") } else {