Skip to content

Commit

Permalink
refactor: use try catch instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Benehiko committed Jun 29, 2023
1 parent 52c1a54 commit 7a6067e
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/routes/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,20 @@ export const createLoginRoute: RouteCreator =
// is also used for 2FA flows. If something goes wrong there, we probably want
// to give the user the option to sign out!
const getLogoutUrl = async (loginFlow: LoginFlow) => {
return (
(
await frontend
.createBrowserLogoutFlow({
cookie: req.header("cookie"),
returnTo:
(return_to && return_to.toString()) ||
loginFlow.return_to ||
"",
} as { cookie: string; returnTo: string })
.catch(() => ({ data: { logout_url: "" } }))
).data.logout_url || ""
)
let logoutUrl = ""
try {
logoutUrl = await frontend
.createBrowserLogoutFlow({
cookie: req.header("cookie"),
returnTo:
(return_to && return_to.toString()) || loginFlow.return_to || "",
})
.then(({ data }) => data.logout_url)
} catch (err) {
logger.error("Unable to create logout URL", { error: err })
} finally {
return logoutUrl
}
}

const redirectToVerificationFlow = (loginFlow: LoginFlow) => {
Expand Down

0 comments on commit 7a6067e

Please sign in to comment.