Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: settings and welcome page should support logout return_to #274

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading