-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update interactive Next.js Quickstart to use the Next.js v4 SDK (#10487)
* Update interactive.md Update interactive quickstart using nextjs v4 beta * Update env.md Edited env file to reflect changes based on V4 quickstart * Create auth0 Created auth0.ts file for quickstart v4 * Rename auth0 to auth0.md renaming * Create middleware.md * Create page.md * Update page.md, remove custom classNames (#10488) Update page.md, remove custom classNames * Update interactive.md Capitalized Beta in line 26 to match earlier styling --------- Co-authored-by: Tushar Pandey <[email protected]> Co-authored-by: rle28 <[email protected]> Co-authored-by: Nick Gagliardi <[email protected]>
- Loading branch information
1 parent
5970c20
commit 4077d3d
Showing
5 changed files
with
125 additions
and
101 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,12 @@ | ||
--- | ||
name: "src/lib/auth0.ts" | ||
language: javascript | ||
--- | ||
|
||
<!-- markdownlint-disable MD041 --> | ||
|
||
```javascript | ||
import { Auth0Client } from "@auth0/nextjs-auth0/server"; | ||
|
||
export const auth0 = new Auth0Client(); | ||
``` |
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,27 @@ | ||
--- | ||
name: "src/middleware.ts" | ||
language: javascript | ||
--- | ||
|
||
<!-- markdownlint-disable MD041 --> | ||
|
||
```javascript | ||
import type { NextRequest } from "next/server"; | ||
import { auth0 } from "./lib/auth0"; | ||
|
||
export async function middleware(request: NextRequest) { | ||
return await auth0.middleware(request); | ||
} | ||
|
||
export const config = { | ||
matcher: [ | ||
/* | ||
* Match all request paths except for the ones starting with: | ||
* - _next/static (static files) | ||
* - _next/image (image optimization files) | ||
* - favicon.ico, sitemap.xml, robots.txt (metadata files) | ||
*/ | ||
"/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)", | ||
], | ||
}; | ||
``` |
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,42 @@ | ||
--- | ||
name: "src/app/page.tsx" | ||
language: javascript | ||
--- | ||
|
||
<!-- markdownlint-disable MD041 --> | ||
|
||
```javascript | ||
import { auth0 } from "@/lib/auth0"; | ||
import './globals.css'; | ||
|
||
export default async function Home() { | ||
// Fetch the user session | ||
const session = await auth0.getSession(); | ||
|
||
// If no session, show sign-up and login buttons | ||
if (!session) { | ||
return ( | ||
<main> | ||
<a href="/auth/login?screen_hint=signup"> | ||
<button>Sign up</button> | ||
</a> | ||
<a href="/auth/login"> | ||
<button>Log in</button> | ||
</a> | ||
</main> | ||
); | ||
} | ||
|
||
// If session exists, show a welcome message and logout button | ||
return ( | ||
<main> | ||
<h1>Welcome, {session.user.name}!</h1> | ||
<p> | ||
<a href="/auth/logout"> | ||
<button>Log out</button> | ||
</a> | ||
</p> | ||
</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