Skip to content

Commit

Permalink
fix: fix issue with return url
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe committed Nov 20, 2023
1 parent 896b41a commit c43986c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/components/ory/hooks.ts
Original file line number Diff line number Diff line change
@@ -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 = (
Expand Down Expand Up @@ -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);
})
Expand All @@ -187,7 +196,8 @@ export function useCreateLogoutHandler(deps?: DependencyList) {
if (logoutToken) {
ory
.updateLogoutFlow({
token: logoutToken
token: logoutToken,
returnTo: returnTo
})
.then(() => push("/"))
.catch((error) => {
Expand Down

0 comments on commit c43986c

Please sign in to comment.