Skip to content

Commit

Permalink
feat: settings and welcome page should support logout return_to (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benehiko authored Aug 7, 2023
1 parent 63e11dd commit 004f7b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
26 changes: 12 additions & 14 deletions src/routes/settings.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -22,7 +19,6 @@ import {
filterNodesByGroups,
isUiNodeInputAttributes,
} from "@ory/integrations/ui"
import { AxiosError } from "axios"
import {
defaultConfig,
getUrlForFlow,
Expand Down Expand Up @@ -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 || ""

Expand All @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion src/routes/welcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || ""

Expand Down

0 comments on commit 004f7b0

Please sign in to comment.