From 018c29bb9c6cb64943f92c9ec6bb728e4c15ef4e Mon Sep 17 00:00:00 2001 From: Alano Terblanche <18033717+Benehiko@users.noreply.github.com> Date: Mon, 7 Aug 2023 11:21:56 +0200 Subject: [PATCH] feat: settings and welcome page should support logout return_to --- src/routes/settings.ts | 26 ++++++++++++-------------- src/routes/welcome.ts | 6 +++++- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/routes/settings.ts b/src/routes/settings.ts index 6861cd77..17ec382d 100644 --- a/src/routes/settings.ts +++ b/src/routes/settings.ts @@ -1,9 +1,6 @@ // Copyright © 2022 Ory Corp // SPDX-License-Identifier: Apache-2.0 -import { - ErrorAuthenticatorAssuranceLevelNotSatisfied, - UiNodeInputAttributes, -} from "@ory/client" +import { UiNodeInputAttributes } from "@ory/client" import { Divider, hasLookupSecret, @@ -22,7 +19,6 @@ import { filterNodesByGroups, isUiNodeInputAttributes, } from "@ory/integrations/ui" -import { AxiosError } from "axios" import { defaultConfig, getUrlForFlow, @@ -59,14 +55,6 @@ export const createSettingsRoute: RouteCreator = const session = req.session - // Create a logout URL - const logoutUrl = - ( - await frontend - .createBrowserLogoutFlow({ cookie: req.header("cookie") }) - .catch(() => ({ data: { logout_url: "" } })) - ).data.logout_url || "" - const identityCredentialTrait = session?.identity.traits.email || session?.identity.traits.username || "" @@ -77,7 +65,17 @@ export const createSettingsRoute: RouteCreator = return frontend .getSettingsFlow({ id: flow, cookie: req.header("cookie") }) - .then(({ data: flow }) => { + .then(async ({ data: flow }) => { + const logoutUrl = + (await frontend + .createBrowserLogoutFlow({ + cookie: req.header("cookie"), + returnTo: + (return_to && return_to.toString()) || flow.return_to || "", + }) + .then(({ data }) => data.logout_url) + .catch(() => "")) || "" + const conditionalLinks: NavSectionLinks[] = [ { name: "Profile", diff --git a/src/routes/welcome.ts b/src/routes/welcome.ts index 3648944f..8d6c524b 100644 --- a/src/routes/welcome.ts +++ b/src/routes/welcome.ts @@ -15,12 +15,16 @@ export const createWelcomeRoute: RouteCreator = const { frontend } = createHelpers(req, res) const session = req.session + const { return_to } = req.query // Create a logout URL const logoutUrl = ( await frontend - .createBrowserLogoutFlow({ cookie: req.header("cookie") }) + .createBrowserLogoutFlow({ + cookie: req.header("cookie"), + returnTo: (return_to && return_to.toString()) || "", + }) .catch(() => ({ data: { logout_url: "" } })) ).data.logout_url || ""