From c43986cec4b3b2eff19d41661b333c107a439821 Mon Sep 17 00:00:00 2001 From: Maina Wycliffe Date: Fri, 17 Nov 2023 19:22:56 +0300 Subject: [PATCH] fix: fix issue with return url --- src/components/ory/hooks.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/components/ory/hooks.ts b/src/components/ory/hooks.ts index 3db811540f..643f5f6a29 100644 --- a/src/components/ory/hooks.ts +++ b/src/components/ory/hooks.ts @@ -1,6 +1,6 @@ import { AxiosError } from "axios"; import Router, { useRouter } from "next/router"; -import { DependencyList, useEffect, useState } from "react"; +import { DependencyList, useEffect, useMemo, useState } from "react"; import ory from "./sdk"; export const HandleError = ( @@ -173,9 +173,18 @@ export function useCreateLogoutHandler(deps?: DependencyList) { const handleError = HandleError(); const { push } = useRouter(); + const returnTo = useMemo(() => { + if (typeof window !== "undefined") { + return window.location.pathname + window.location.search; + } + return undefined; + }, []); + useEffect(() => { ory - .createBrowserLogoutFlow() + .createBrowserLogoutFlow({ + returnTo: returnTo + }) .then(({ data }) => { setLogoutToken(data.logout_token); }) @@ -187,7 +196,8 @@ export function useCreateLogoutHandler(deps?: DependencyList) { if (logoutToken) { ory .updateLogoutFlow({ - token: logoutToken + token: logoutToken, + returnTo: returnTo }) .then(() => push("/")) .catch((error) => {