diff --git a/e2e/playwright/auth.spec.ts b/e2e/playwright/auth.spec.ts index eae4051dd..f9c290964 100644 --- a/e2e/playwright/auth.spec.ts +++ b/e2e/playwright/auth.spec.ts @@ -13,12 +13,22 @@ test.describe('Authentication tests', () => { await page.setBodyDimensions({ width: 1000, height: 500 }) await homePage.projectSection.waitFor() + // This is only needed as an override to test-utils' setup() for this test + await page.addInitScript(() => { + localStorage.setItem('TOKEN_PERSIST_KEY', '') + }) + await test.step('Click on sign out and expect sign in page', async () => { await toolbar.userSidebarButton.click() await toolbar.signOutButton.click() await expect(signInPage.signInButton).toBeVisible() }) + await test.step("Refresh doesn't log the user back in", async () => { + await page.reload() + await expect(signInPage.signInButton).toBeVisible() + }) + await test.step('Click on sign in and cancel, click again and expect different code', async () => { await signInPage.signInButton.click() await expect(signInPage.userCode).toBeVisible() @@ -30,6 +40,7 @@ test.describe('Authentication tests', () => { await expect(signInPage.userCode).toBeVisible() const secondUserCode = await signInPage.userCode.textContent() expect(secondUserCode).not.toEqual(firstUserCode) + await signInPage.cancelSignInButton.click() }) await test.step('Press back button and remain on home page', async () => { @@ -48,6 +59,12 @@ test.describe('Authentication tests', () => { // Longer timeout than usual here for the wait on home page await expect(homePage.projectSection).toBeVisible({ timeout: 10000 }) }) + + await test.step('Click on sign out and expect sign in page', async () => { + await toolbar.userSidebarButton.click() + await toolbar.signOutButton.click() + await expect(signInPage.signInButton).toBeVisible() + }) } ) }) diff --git a/src/machines/authMachine.ts b/src/machines/authMachine.ts index 7061128bf..0f69597e1 100644 --- a/src/machines/authMachine.ts +++ b/src/machines/authMachine.ts @@ -78,9 +78,7 @@ export const authMachine = setup({ getUser: fromPromise(({ input }: { input: { token?: string } }) => getUser(input) ), - logout: fromPromise(async () => - isDesktop() ? writeTokenFile('') : logout() - ), + logout: fromPromise(logout), }, }).createMachine({ /** @xstate-layout N4IgpgJg5mDOIC5QEECuAXAFgOgMabFwGsBJAMwBkB7KGCEgOwGIIqGxsBLBgNyqI75CRALQAbGnRHcA2gAYAuolAAHKrE7pObZSAAeiAIwAWQ9gBspuQCYAnAGYAHPYCsx+4ccAaEAE9E1q7YcoZyxrYR1m7mcrYAvnE+aFh4BMTk1LSQjExgAE55VHnYKmIAhuhkRQC2qcLikpDSDPJKSCBqGlo67QYI9gDs5tge5o6h5vau7oY+-v3mA9jWco4u5iu21ua2YcYJSRg4Eln0zJkABFQYrbqdmtoMun2GA7YjxuPmLqvGNh5zRCfJaOcyLUzuAYuFyGcwHEDJY6NCAAeQwTEuskUd3UDx6oD6Im2wUcAzkMJ2cjBxlMgIWLmwZLWljecjJTjh8IYVAgcF0iJxXUez0QIgGxhJZIpu2ptL8AWwtje1nCW2iq1shns8MRdXSlGRjEFeKevUQjkcy3sqwGHimbg83nlCF22GMytVUWMMUc8USCKO2BOdCN7Xu3VNBKMKsVFp2hm2vu+1id83slkVrgTxhcW0pNJ1geDkDR6GNEZFCAT1kZZLk9cMLltb0WdPMjewjjC1mzOZCtk5CSAA */ @@ -254,7 +252,11 @@ async function getAndSyncStoredToken(input: { async function logout() { localStorage.removeItem(TOKEN_PERSIST_KEY) - if (isDesktop()) return Promise.resolve(null) + if (isDesktop()) { + await writeTokenFile('') + return Promise.resolve(null) + } + return fetch(withBaseUrl('/logout'), { method: 'POST', credentials: 'include',