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) => {