Skip to content

Commit

Permalink
fix(request) avoid using request url in the ui. fixes #289
Browse files Browse the repository at this point in the history
Signed-off-by: David Edler <david.edler@canonical.com>
  • Loading branch information
edlerd committed Sep 30, 2024
1 parent 3883fa3 commit d53dcad
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 32 deletions.
7 changes: 7 additions & 0 deletions ui/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ const Login: NextPage = () => {
window.location.href = data.redirect_to;
return;
}
if (flowId !== data.id) {
window.history.replaceState(
null,
"",
`./reset_password?flow=${data.id}`,
);
}
setFlow(data);
})
.catch(handleFlowError("login", setFlow))
Expand Down
16 changes: 6 additions & 10 deletions ui/pages/reset_email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,13 @@ const ResetEmail: NextPage = () => {
.createBrowserRecoveryFlow({
returnTo: returnTo ? String(returnTo) : undefined,
})
.then(async ({ data }) => {
if (data.request_url !== undefined) {
await router.push(
{
pathname: "reset_email",
query: { flow: data.id },
},
`${data.return_to}?flow=${data.id}`,
{ shallow: true },
.then(({ data }) => {
if (flowId !== data.id) {
window.history.replaceState(
null,
"",
`./reset_email?flow=${data.id}`,
);
return;
}
setFlow(data);
})
Expand Down
9 changes: 6 additions & 3 deletions ui/pages/reset_password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ const ResetPassword: NextPage = () => {
returnTo: returnTo ? String(returnTo) : undefined,
})
.then(({ data }) => {
if (data.request_url !== undefined) {
window.location.href = data.request_url;
return;
if (flowId !== data.id) {
window.history.replaceState(
null,
"",
`./reset_password?flow=${data.id}`,
);
}
setFlow(data);
})
Expand Down
9 changes: 6 additions & 3 deletions ui/pages/setup_backup_codes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ const SetupBackupCodes: NextPage = () => {
returnTo: returnTo ? String(returnTo) : undefined,
})
.then(({ data }) => {
if (data.request_url !== undefined) {
window.location.href = `./setup_backup_codes?flow=${data.id}`;
return;
if (flowId !== data.id) {
window.history.replaceState(
null,
"",
`./setup_backup_codes?flow=${data.id}`,
);
}
setFlow(data);
})
Expand Down
9 changes: 6 additions & 3 deletions ui/pages/setup_passkey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ const SetupPasskey: NextPage = () => {
returnTo: returnTo ? String(returnTo) : undefined,
})
.then(({ data }) => {
if (data.request_url !== undefined) {
window.location.href = `./setup_passkey?flow=${data.id}`;
return;
if (flowId !== data.id) {
window.history.replaceState(
null,
"",
`./setup_passkey?flow=${data.id}`,
);
}
setFlow(data);
})
Expand Down
22 changes: 9 additions & 13 deletions ui/pages/setup_secure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,15 @@ const SetupSecure: NextPage = () => {
? returnTo.toString()
: window.location.pathname.replace("setup_secure", "setup_complete"),
})
.then(async ({ data }) => {
const pwParam = pwChanged ? pwChanged.toString() : "false";
router.query.flow = data.id;
router.query.pw_changed = pwParam;

await router.replace(
{
pathname: window.location.pathname,
query: router.query,
},
undefined,
{ shallow: true },
);
.then(({ data }) => {
const pwParam = pwChanged ? `&pw_changed=${pwChanged.toString()}` : "";
if (flowId !== data.id) {
window.history.replaceState(
null,
"",
`./reset_password?flow=${data.id}${pwParam}`,
);
}
setFlow(data);
})
.catch(handleFlowError("settings", setFlow))
Expand Down

0 comments on commit d53dcad

Please sign in to comment.