Skip to content

Commit 7f45c90

Browse files
committed
add e2e
1 parent 3f85a90 commit 7f45c90

File tree

6 files changed

+65
-0
lines changed

6 files changed

+65
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { forbidden } from "next/navigation";
2+
3+
export default function Page() {
4+
forbidden();
5+
6+
// this should never be rendered
7+
return <></>;
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { unauthorized } from "next/navigation";
2+
3+
export default function Page() {
4+
unauthorized();
5+
6+
// this should never be rendered
7+
return <></>;
8+
}

examples/app-router/app/forbidden.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Link from "next/link";
2+
3+
export default function Forbidden() {
4+
return (
5+
<div>
6+
<h2>Forbidden</h2>
7+
<p>You are not authorized to access this resource.</p>
8+
<Link href="/">Return Home</Link>
9+
</div>
10+
);
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Unauthorized() {
2+
return (
3+
<div>
4+
<h2>Unauthorized</h2>
5+
</div>
6+
);
7+
}

examples/app-router/next.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const nextConfig: NextConfig = {
1717
},
1818
],
1919
},
20+
experimental: {
21+
authInterrupts: true,
22+
},
2023
redirects: async () => {
2124
return [
2225
{
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
const NO_CACHE_HEADER =
4+
"private, no-cache, no-store, max-age=0, must-revalidate";
5+
6+
test("test forbidden", async ({ page }) => {
7+
const result = await page.goto("/auth-interrupts/forbidden");
8+
expect(result).toBeDefined();
9+
expect(result?.status()).toBe(403);
10+
11+
const headers = result?.headers();
12+
expect(headers?.["cache-control"]).toBe(NO_CACHE_HEADER);
13+
14+
const heading = page.getByText("Forbidden");
15+
await expect(heading).toBeVisible();
16+
});
17+
18+
test("test unauthorized", async ({ page }) => {
19+
const result = await page.goto("/auth-interrupts/unauthorized");
20+
expect(result).toBeDefined();
21+
expect(result?.status()).toBe(401);
22+
23+
const headers = result?.headers();
24+
expect(headers?.["cache-control"]).toBe(NO_CACHE_HEADER);
25+
26+
const heading = page.getByText("Unauthorized");
27+
await expect(heading).toBeVisible();
28+
});

0 commit comments

Comments
 (0)