Skip to content

Commit 06bf723

Browse files
committed
fix(site): fix redirection to login after logout/change password
1 parent 311327c commit 06bf723

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

site/e2e/tests/logout.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { test, expect } from "@playwright/test"
2+
import { getStatePath } from "../helpers"
3+
4+
test.use({ storageState: getStatePath("authState") })
5+
6+
test("signing out redirects to login page", async ({ page, baseURL }) => {
7+
await page.goto(`${baseURL}/`, { waitUntil: "networkidle" })
8+
9+
await page.getByTestId("user-dropdown-trigger").click()
10+
await page.getByRole("menuitem", { name: "Sign Out" }).click()
11+
12+
await expect(page.getByRole("heading", { name: "Sign in to Coder" })).toBeVisible()
13+
})

site/src/pages/UserSettingsPage/SecurityPage/SecurityPage.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ describe("SecurityPage", () => {
4747
expect(successMessage).toBeDefined()
4848
expect(API.updateUserPassword).toBeCalledTimes(1)
4949
expect(API.updateUserPassword).toBeCalledWith(user.id, newData)
50+
51+
await waitFor(() => expect(window.location).toBeAt("/"))
5052
})
5153
})
5254

site/src/xServices/auth/authXService.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,10 @@ export const authMachine =
389389
}),
390390
redirect: (_, { data }) => {
391391
if (!("redirectUrl" in data)) {
392-
throw new Error(
393-
"Redirect only should be called with data.redirectUrl",
394-
)
392+
window.location.href = location.origin
393+
} else {
394+
window.location.replace(data.redirectUrl)
395395
}
396-
397-
window.location.replace(data.redirectUrl)
398396
},
399397
},
400398
guards: {

site/src/xServices/userSecuritySettings/userSecuritySettingsXService.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const userSecuritySettingsMachine = createMachine(
3535
src: "updateSecurity",
3636
onDone: [
3737
{
38-
actions: "notifyUpdate",
38+
actions: ["notifyUpdate", "redirectToHome"],
3939
target: "idle",
4040
},
4141
],
@@ -66,6 +66,9 @@ export const userSecuritySettingsMachine = createMachine(
6666
assignError: assign({
6767
error: (_, event) => event.data,
6868
}),
69+
redirectToHome: () => {
70+
window.location.href = location.origin
71+
}
6972
},
7073
},
7174
)

0 commit comments

Comments
 (0)