Skip to content

Commit 403ad83

Browse files
committed
test(e2e): Add test for accessing cached protected route after sign-out
1 parent f7bff86 commit 403ad83

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎integration/templates/next-app-router/src/app/page.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default function Home() {
1717
<ul>
1818
<li>
1919
<Link href='/page-protected'>Page Protected</Link>
20+
<Link href='/protected'>Protected</Link>
2021
</li>
2122
</ul>
2223
</main>
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import Link from 'next/link';
2+
13
export default function Page() {
2-
return <div>Protected</div>;
4+
return (
5+
<>
6+
<div data-testid='protected'>Protected</div>
7+
<Link href='/'>Home</Link>
8+
</>
9+
);
310
}

‎integration/tests/sign-out-smoke.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('sign out
6868
const client_id_after_sign_out = await u.page.locator('p[data-clerk-id]').innerHTML();
6969
expect(client_id).toEqual(client_id_after_sign_out);
7070
});
71+
72+
test('Protected routes do not persist after sign out', async ({ page, context }) => {
73+
const u = createTestUtils({ app, page, context });
74+
75+
await u.po.signIn.goTo();
76+
await u.po.signIn.waitForMounted();
77+
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
78+
await u.po.expect.toBeSignedIn();
79+
80+
await u.page.getByRole('link', { name: 'Protected', exact: true }).click();
81+
await u.page.getByTestId('protected').waitFor();
82+
await u.page.getByRole('link', { name: 'Home' }).click();
83+
await u.page.getByRole('button', { name: 'Open user button' }).click();
84+
85+
await u.page.getByRole('menuitem', { name: 'Sign out' }).click();
86+
await u.page.getByRole('link', { name: 'Protected', exact: true }).click();
87+
await u.page.waitForURL(/sign-in\?redirect_url/);
88+
});
7189
});
7290

7391
testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes_destroy_client] })(

0 commit comments

Comments
 (0)