From 3e80f3676f43e2f018c3b5e24e601a7ba7337c81 Mon Sep 17 00:00:00 2001 From: mit-27 Date: Sat, 20 Apr 2024 12:11:52 -0400 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Fix=20protected=20route=20re?= =?UTF-8?q?direct?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/client-ts/src/app/api-keys/layout.tsx | 6 +++--- apps/client-ts/src/app/b2c/profile/layout.tsx | 6 +++--- apps/client-ts/src/app/configuration/layout.tsx | 9 +++++---- apps/client-ts/src/app/connections/layout.tsx | 7 +++---- apps/client-ts/src/app/dashboard/layout.tsx | 6 +++--- apps/client-ts/src/app/events/layout.tsx | 4 ++-- apps/client-ts/src/components/Nav/user-nav.tsx | 2 +- apps/client-ts/src/components/RootLayout/index.tsx | 2 +- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/apps/client-ts/src/app/api-keys/layout.tsx b/apps/client-ts/src/app/api-keys/layout.tsx index c71e65eb4..b291e97b0 100644 --- a/apps/client-ts/src/app/api-keys/layout.tsx +++ b/apps/client-ts/src/app/api-keys/layout.tsx @@ -12,13 +12,13 @@ export default function Layout({ }: Readonly<{ children: React.ReactNode; }>) { - const { session } = useStytchSession(); + const { session,isInitialized } = useStytchSession(); const router = useRouter(); useEffect(() => { - if(config.DISTRIBUTION !== "selfhost" && !session){ + if(config.DISTRIBUTION !== "selfhosted" && isInitialized && !session){ router.replace("/b2c/login"); } - }, [session, router]); + }, [session,isInitialized, router]); return ( <> diff --git a/apps/client-ts/src/app/b2c/profile/layout.tsx b/apps/client-ts/src/app/b2c/profile/layout.tsx index 06543bdaf..e93ce7861 100644 --- a/apps/client-ts/src/app/b2c/profile/layout.tsx +++ b/apps/client-ts/src/app/b2c/profile/layout.tsx @@ -11,13 +11,13 @@ export default function Layout({ }: Readonly<{ children: React.ReactNode; }>) { - const { session } = useStytchSession(); + const { session,isInitialized } = useStytchSession(); const router = useRouter(); useEffect(() => { - if (!session) { + if (isInitialized && !session) { router.replace("/b2c/login"); } - }, [session, router]); + }, [session, isInitialized, router]); console.log('WEBAPP DOMAIN is '+ process.env.NEXT_PUBLIC_WEBAPP_DOMAIN) return ( diff --git a/apps/client-ts/src/app/configuration/layout.tsx b/apps/client-ts/src/app/configuration/layout.tsx index 3df15b368..38ce8043d 100644 --- a/apps/client-ts/src/app/configuration/layout.tsx +++ b/apps/client-ts/src/app/configuration/layout.tsx @@ -12,13 +12,14 @@ export default function Layout({ }: Readonly<{ children: React.ReactNode; }>) { - const { session } = useStytchSession(); + const { session,isInitialized } = useStytchSession(); + const router = useRouter(); - useEffect(() => { - if(config.DISTRIBUTION !== "selfhost" && !session){ + useEffect(() => { + if(config.DISTRIBUTION !== "selfhosted" && isInitialized && !session){ router.push("/b2c/login"); } - }, [session, router]); + }, [session, isInitialized, router]); return ( <> diff --git a/apps/client-ts/src/app/connections/layout.tsx b/apps/client-ts/src/app/connections/layout.tsx index 8b1d902eb..1ff2e6a2f 100644 --- a/apps/client-ts/src/app/connections/layout.tsx +++ b/apps/client-ts/src/app/connections/layout.tsx @@ -14,14 +14,13 @@ export default function Layout({ }: Readonly<{ children: React.ReactNode; }>) { - const { session } = useStytchSession(); - console.log("session inside connections page is "+ JSON.stringify(session)) + const { session,isInitialized } = useStytchSession(); const router = useRouter(); useEffect(() => { - if(config.DISTRIBUTION !== "selfhost" && !session){ + if(config.DISTRIBUTION !== "selfhosted" && isInitialized && !session){ router.push("/b2c/login"); } - }, [session, router]); + }, [session,isInitialized, router]); return ( <> diff --git a/apps/client-ts/src/app/dashboard/layout.tsx b/apps/client-ts/src/app/dashboard/layout.tsx index 7a17ef981..3d766efc6 100644 --- a/apps/client-ts/src/app/dashboard/layout.tsx +++ b/apps/client-ts/src/app/dashboard/layout.tsx @@ -14,13 +14,13 @@ export default function Layout({ }: Readonly<{ children: React.ReactNode; }>) { - const { session } = useStytchSession(); + const { session,isInitialized } = useStytchSession(); const router = useRouter(); useEffect(() => { - if(config.DISTRIBUTION !== "selfhost" && !session){ + if(config.DISTRIBUTION !== "selfhosted" && isInitialized && !session){ router.replace("/b2c/login"); } - }, [session, router]); + }, [session,isInitialized, router]); return ( <> diff --git a/apps/client-ts/src/app/events/layout.tsx b/apps/client-ts/src/app/events/layout.tsx index 5f4760322..6916486b2 100644 --- a/apps/client-ts/src/app/events/layout.tsx +++ b/apps/client-ts/src/app/events/layout.tsx @@ -18,10 +18,10 @@ export default function Layout({ const router = useRouter(); useEffect(() => { - if(config.DISTRIBUTION !== "selfhost" && !session){ + if(config.DISTRIBUTION !== "selfhosted" && isInitialized && !session){ router.replace("/b2c/login"); } - }, [session, router]); + }, [session,isInitialized, router]); return ( <> diff --git a/apps/client-ts/src/components/Nav/user-nav.tsx b/apps/client-ts/src/components/Nav/user-nav.tsx index 3ddd9db84..e6a4d5ac0 100644 --- a/apps/client-ts/src/components/Nav/user-nav.tsx +++ b/apps/client-ts/src/components/Nav/user-nav.tsx @@ -59,7 +59,7 @@ export function UserNav() { - + Profile diff --git a/apps/client-ts/src/components/RootLayout/index.tsx b/apps/client-ts/src/components/RootLayout/index.tsx index 55aceb00a..595558d07 100644 --- a/apps/client-ts/src/components/RootLayout/index.tsx +++ b/apps/client-ts/src/components/RootLayout/index.tsx @@ -65,7 +65,7 @@ export const RootLayout = () => { onLinkClick={handlePageChange} /> { - config.DISTRIBUTION == "managed" && + config.DISTRIBUTION === "managed" && (
From cc59c0569eb5375064a46523703b41f6d90bd60a Mon Sep 17 00:00:00 2001 From: mit-27 Date: Sat, 20 Apr 2024 13:56:10 -0400 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20Fix=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/client-ts/src/components/Nav/user-nav.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/apps/client-ts/src/components/Nav/user-nav.tsx b/apps/client-ts/src/components/Nav/user-nav.tsx index e6a4d5ac0..7eb14c9f2 100644 --- a/apps/client-ts/src/components/Nav/user-nav.tsx +++ b/apps/client-ts/src/components/Nav/user-nav.tsx @@ -16,12 +16,15 @@ import { import { Skeleton } from "@/components/ui/skeleton"; import useProfile from "@/hooks/useProfile"; import useProfileStore from "@/state/profileStore"; -import { useStytchUser } from "@stytch/nextjs"; +import { useStytchUser,useStytch } from "@stytch/nextjs"; +import { useRouter } from "next/navigation"; import Link from "next/link"; import { useEffect } from "react"; export function UserNav() { + const stytch = useStytch(); const { user } = useStytchUser(); + const router = useRouter(); const {data, isLoading} = useProfile(user?.user_id!); if(!data) { console.log("loading profiles"); @@ -40,6 +43,10 @@ export function UserNav() { } }, [data, setProfile]); + const onLogout = () => { + stytch.session.revoke() + router.push('/b2c/login'); + } return ( @@ -72,11 +79,9 @@ export function UserNav() { */} - - + onLogout()} > Log out - - + )