Skip to content

Commit

Permalink
feat: add MA application check for signed-in user (#3850)
Browse files Browse the repository at this point in the history
  • Loading branch information
cliu02 authored Feb 12, 2024
1 parent 841523c commit 091df62
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions shared-helpers/src/auth/UseRequireLoggedInUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions sites/public/src/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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

Expand Down
9 changes: 4 additions & 5 deletions sites/public/src/pages/applications/start/choose-language.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 091df62

Please sign in to comment.