Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
fix: sign in popup doesn't close
Browse files Browse the repository at this point in the history
  • Loading branch information
intergalacticspacehighway committed Nov 20, 2023
1 parent 5868475 commit 00a67cf
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/app/hooks/use-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { useContext, useEffect } from "react";
import { useRouter } from "@showtime-xyz/universal.router";

import { UserContext } from "app/context/user-context";
import { useNavigateToOnboarding } from "app/navigation/use-navigate-to";
import {
useNavigateToLogin,
useNavigateToOnboarding,
} from "app/navigation/use-navigate-to";

type UserParams = {
redirectTo?: string;
Expand All @@ -13,9 +16,14 @@ export function useUser(params?: UserParams) {
const context = useContext(UserContext);
const router = useRouter();
const navigateToOnboarding = useNavigateToOnboarding();
const navigateToLogin = useNavigateToLogin();
useEffect(() => {
if (!context?.isAuthenticated && params?.redirectTo && router) {
router.replace(params?.redirectTo);
if (params.redirectTo === "/login") {
navigateToLogin();
} else {
router.replace(params?.redirectTo);
}
}
if (
context?.isAuthenticated &&
Expand All @@ -28,6 +36,7 @@ export function useUser(params?: UserParams) {
}, [
context?.isAuthenticated,
context?.isIncompletedProfile,
navigateToLogin,
navigateToOnboarding,
params?.redirectIfProfileIncomplete,
params?.redirectTo,
Expand Down

0 comments on commit 00a67cf

Please sign in to comment.