Skip to content

fix(site): fix redirection to login after logout/change password #6870

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

Merged
merged 5 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix(site): fix redirection to login after logout/change password
  • Loading branch information
rodrimaia committed Mar 29, 2023
commit 56e6ca63b33fb58e7b7e996c9f6b688fce71ed5b
13 changes: 13 additions & 0 deletions site/e2e/tests/logout.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { test, expect } from "@playwright/test"
import { getStatePath } from "../helpers"

test.use({ storageState: getStatePath("authState") })

test("signing out redirects to login page", async ({ page, baseURL }) => {
await page.goto(`${baseURL}/`, { waitUntil: "networkidle" })

await page.getByTestId("user-dropdown-trigger").click()
await page.getByRole("menuitem", { name: "Sign Out" }).click()

await expect(page.getByRole("heading", { name: "Sign in to Coder" })).toBeVisible()
})
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ describe("SecurityPage", () => {
expect(successMessage).toBeDefined()
expect(API.updateUserPassword).toBeCalledTimes(1)
expect(API.updateUserPassword).toBeCalledWith(user.id, newData)

await waitFor(() => expect(window.location).toBeAt("/"))
})
})

Expand Down
8 changes: 3 additions & 5 deletions site/src/xServices/auth/authXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,10 @@ export const authMachine =
}),
redirect: (_, { data }) => {
if (!("redirectUrl" in data)) {
throw new Error(
"Redirect only should be called with data.redirectUrl",
)
window.location.href = location.origin
} else {
window.location.replace(data.redirectUrl)
}

window.location.replace(data.redirectUrl)
},
},
guards: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const userSecuritySettingsMachine = createMachine(
src: "updateSecurity",
onDone: [
{
actions: "notifyUpdate",
actions: ["notifyUpdate", "redirectToHome"],
target: "idle",
},
],
Expand Down Expand Up @@ -66,6 +66,9 @@ export const userSecuritySettingsMachine = createMachine(
assignError: assign({
error: (_, event) => event.data,
}),
redirectToHome: () => {
window.location.href = location.origin
}
},
},
)