Skip to content

Commit

Permalink
feat: settings and welcome page should support logout return_to
Browse files Browse the repository at this point in the history
  • Loading branch information
Benehiko committed Aug 7, 2023
1 parent 63e11dd commit 5c96289
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
36 changes: 17 additions & 19 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 Expand Up @@ -146,11 +144,11 @@ export const createSettingsRoute: RouteCreator =
}),
sessionDescription: [
sessionText !== "" &&
Typography({
children: sessionText,
color: "foregroundMuted",
size: "small",
}),
Typography({
children: sessionText,
color: "foregroundMuted",
size: "small",
}),
Typography({
children:
"Here you can manage settings related to your account. Keep in mind that certain actions require you to re-authenticate.",
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 5c96289

Please sign in to comment.