-
Notifications
You must be signed in to change notification settings - Fork 396
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
4,426 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Playwright Tests | ||
on: | ||
push: | ||
branches: [ main, master ] | ||
pull_request: | ||
branches: [ main, master ] | ||
jobs: | ||
test: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
- name: Install dependencies | ||
run: npm install -g pnpm && pnpm install | ||
- name: Install Playwright Browsers | ||
run: pnpm exec playwright install --with-deps | ||
- name: Run Playwright tests | ||
run: pnpm exec playwright test | ||
- uses: actions/upload-artifact@v4 | ||
if: ${{ !cancelled() }} | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { expect, test } from "@playwright/test" | ||
|
||
test("getSession()", async ({ page }) => { | ||
await page.goto("/auth/login?returnTo=/app-router/server") | ||
|
||
// fill out Auth0 form | ||
await page.fill('input[id="username"]', "[email protected]") | ||
await page.fill('input[id="password"]', process.env.TEST_USER_PASSWORD!) | ||
await page.getByText("Continue", { exact: true }).click() | ||
|
||
// check that the page says "Welcome, [email protected]!" | ||
expect(await page.getByRole("heading", { level: 1 }).textContent()).toBe( | ||
"Welcome, [email protected]!" | ||
) | ||
|
||
// ensure we're redirected back to the home page on logout | ||
await page.goto("/auth/logout") | ||
expect(await page.getByRole("heading", { level: 1 }).textContent()).toBe( | ||
"Home" | ||
) | ||
|
||
// check that `getSession()` returns null after logging out | ||
await page.goto("/app-router/server") | ||
expect(page.getByRole("link", { name: "Log in" })).toBeVisible() | ||
}) | ||
|
||
test("useUser()", async ({ page }) => { | ||
await page.goto("/auth/login?returnTo=/app-router/client") | ||
|
||
// fill out Auth0 form | ||
await page.fill('input[id="username"]', "[email protected]") | ||
await page.fill('input[id="password"]', process.env.TEST_USER_PASSWORD!) | ||
await page.getByText("Continue", { exact: true }).click() | ||
|
||
// check that the page says "Welcome, [email protected]!" | ||
expect(await page.getByRole("heading", { level: 1 }).textContent()).toBe( | ||
"Welcome, [email protected]!" | ||
) | ||
|
||
// ensure we're redirected back to the home page on logout | ||
await page.goto("/auth/logout") | ||
expect(await page.getByRole("heading", { level: 1 }).textContent()).toBe( | ||
"Home" | ||
) | ||
|
||
// check that `getSession()` returns null after logging out | ||
await page.goto("/app-router/client") | ||
expect(page.getByRole("link", { name: "Log in" })).toBeVisible() | ||
}) | ||
|
||
test("getAccessToken()", async ({ page }) => { | ||
await page.goto("/auth/login?returnTo=/app-router/client") | ||
|
||
// fill out Auth0 form | ||
await page.fill('input[id="username"]', "[email protected]") | ||
await page.fill('input[id="password"]', process.env.TEST_USER_PASSWORD!) | ||
await page.getByText("Continue", { exact: true }).click() | ||
|
||
// fetch a token | ||
const requestPromise = page.waitForRequest("/auth/access-token") | ||
await page.getByText("Get token").click() | ||
const request = await requestPromise | ||
const tokenRequest = await (await request.response())?.json() | ||
expect(tokenRequest).toHaveProperty("token") | ||
expect(tokenRequest).toHaveProperty("expires_at") | ||
}) | ||
|
||
test("protected server route", async ({ page, request, context }) => { | ||
// before establishing a session, we should receive a 401 | ||
const unauthedRes = await context.request.fetch("/app-router/api/test") | ||
expect(unauthedRes.status()).toBe(401) | ||
|
||
await page.goto("/auth/login?returnTo=/app-router/server") | ||
|
||
// fill out Auth0 form | ||
await page.fill('input[id="username"]', "[email protected]") | ||
await page.fill('input[id="password"]', process.env.TEST_USER_PASSWORD!) | ||
await page.getByText("Continue", { exact: true }).click() | ||
|
||
// after establishing a session, we should receive a 200 | ||
const authedRes = await context.request.fetch("/app-router/api/test") | ||
expect(authedRes.status()).toBe(200) | ||
expect(await authedRes.json()).toEqual({ email: "[email protected]" }) | ||
}) | ||
|
||
test("protected server action", async ({ page }) => { | ||
await page.goto("/app-router/action") | ||
|
||
// call protected server action | ||
await page.getByText("Call server action").click() | ||
await expect(page.locator("#status")).toHaveValue("unauthenticated") | ||
|
||
await page.goto("/auth/login?returnTo=/app-router/action") | ||
|
||
// fill out Auth0 form | ||
await page.fill('input[id="username"]', "[email protected]") | ||
await page.fill('input[id="password"]', process.env.TEST_USER_PASSWORD!) | ||
await page.getByText("Continue", { exact: true }).click() | ||
|
||
// call protected server action, now authenticated | ||
await page.getByText("Call server action").click() | ||
await expect(page.locator("#status")).toHaveValue("authenticated") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { expect, test } from "@playwright/test" | ||
|
||
test("getSession()", async ({ page }) => { | ||
await page.goto("/auth/login?returnTo=/pages-router/server") | ||
|
||
// fill out Auth0 form | ||
await page.fill('input[id="username"]', "[email protected]") | ||
await page.fill('input[id="password"]', process.env.TEST_USER_PASSWORD!) | ||
await page.getByText("Continue", { exact: true }).click() | ||
|
||
// check that the page says "Welcome, [email protected]!" | ||
expect(await page.getByRole("heading", { level: 1 }).textContent()).toBe( | ||
"Welcome, [email protected]!" | ||
) | ||
|
||
// ensure we're redirected back to the home page on logout | ||
await page.goto("/auth/logout") | ||
expect(await page.getByRole("heading", { level: 1 }).textContent()).toBe( | ||
"Home" | ||
) | ||
|
||
// check that `getSession()` returns null after logging out | ||
await page.goto("/pages-router/server") | ||
expect(page.getByRole("link", { name: "Log in" })).toBeVisible() | ||
}) | ||
|
||
test("useUser()", async ({ page }) => { | ||
await page.goto("/auth/login?returnTo=/pages-router/client") | ||
|
||
// fill out Auth0 form | ||
await page.fill('input[id="username"]', "[email protected]") | ||
await page.fill('input[id="password"]', process.env.TEST_USER_PASSWORD!) | ||
await page.getByText("Continue", { exact: true }).click() | ||
|
||
// check that the page says "Welcome, [email protected]!" | ||
expect(await page.getByRole("heading", { level: 1 }).textContent()).toBe( | ||
"Welcome, [email protected]!" | ||
) | ||
|
||
// ensure we're redirected back to the home page on logout | ||
await page.goto("/auth/logout") | ||
expect(await page.getByRole("heading", { level: 1 }).textContent()).toBe( | ||
"Home" | ||
) | ||
|
||
// check that `getSession()` returns null after logging out | ||
await page.goto("/pages-router/client") | ||
expect(page.getByRole("link", { name: "Log in" })).toBeVisible() | ||
}) | ||
|
||
test("getAccessToken()", async ({ page }) => { | ||
await page.goto("/auth/login?returnTo=/pages-router/client") | ||
|
||
// fill out Auth0 form | ||
await page.fill('input[id="username"]', "[email protected]") | ||
await page.fill('input[id="password"]', process.env.TEST_USER_PASSWORD!) | ||
await page.getByText("Continue", { exact: true }).click() | ||
|
||
// fetch a token | ||
const requestPromise = page.waitForRequest("/auth/access-token") | ||
await page.getByText("Get token").click() | ||
const request = await requestPromise | ||
const tokenRequest = await (await request.response())?.json() | ||
expect(tokenRequest).toHaveProperty("token") | ||
expect(tokenRequest).toHaveProperty("expires_at") | ||
}) | ||
|
||
test("protected API route", async ({ page, request, context }) => { | ||
// before establishing a session, we should receive a 401 | ||
const unauthedRes = await context.request.fetch("/api/pages-router/test") | ||
expect(unauthedRes.status()).toBe(401) | ||
|
||
await page.goto("/auth/login?returnTo=/pages-router/server") | ||
|
||
// fill out Auth0 form | ||
await page.fill('input[id="username"]', "[email protected]") | ||
await page.fill('input[id="password"]', process.env.TEST_USER_PASSWORD!) | ||
await page.getByText("Continue", { exact: true }).click() | ||
|
||
// after establishing a session, we should receive a 200 | ||
const authedRes = await context.request.fetch("/api/pages-router/test") | ||
expect(authedRes.status()).toBe(200) | ||
expect(await authedRes.json()).toEqual({ email: "[email protected]" }) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": ["next/core-web-vitals", "next/typescript"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.* | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/versions | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# env files (can opt-in for committing if needed) | ||
.env* | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app). | ||
|
||
## Getting Started | ||
|
||
First, run the development server: | ||
|
||
```bash | ||
npm run dev | ||
# or | ||
yarn dev | ||
# or | ||
pnpm dev | ||
# or | ||
bun dev | ||
``` | ||
|
||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
||
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. | ||
|
||
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel. | ||
|
||
## Learn More | ||
|
||
To learn more about Next.js, take a look at the following resources: | ||
|
||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. | ||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. | ||
|
||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome! | ||
|
||
## Deploy on Vercel | ||
|
||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. | ||
|
||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"use server" | ||
|
||
import { auth0 } from "@/lib/auth0" | ||
|
||
export async function testServerAction() { | ||
const session = await auth0.getSession() | ||
|
||
if (!session) { | ||
return { status: "unauthenticated" } | ||
} | ||
|
||
return { | ||
status: "authenticated", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"use client" | ||
|
||
import { useState } from "react" | ||
|
||
import { testServerAction } from "./action" | ||
|
||
export default function Profile() { | ||
const [status, setStatus] = useState("") | ||
|
||
return ( | ||
<main> | ||
<input | ||
id="status" | ||
value={status} | ||
onChange={(e) => setStatus(e.target.value)} | ||
></input> | ||
<button | ||
onClick={async () => { | ||
const { status } = await testServerAction() | ||
setStatus(status) | ||
}} | ||
> | ||
Call server action | ||
</button> | ||
</main> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { NextResponse } from "next/server" | ||
|
||
import { auth0 } from "@/lib/auth0" | ||
|
||
export async function GET() { | ||
const session = await auth0.getSession() | ||
|
||
if (!session) { | ||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 }) | ||
} | ||
|
||
return NextResponse.json({ email: session.user.email }, { status: 200 }) | ||
} |
Oops, something went wrong.