Skip to content

Commit

Permalink
4.0.0-beta.3 (#1800)
Browse files Browse the repository at this point in the history
  • Loading branch information
guabu authored Nov 14, 2024
1 parent 4f0a528 commit 18da6fb
Show file tree
Hide file tree
Showing 36 changed files with 4,366 additions and 310 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,23 @@ The second option is through the query parameters to the `/auth/login` endpoint
<a href="/auth/login?audience=urn:my-api">Login</a>
```

## The `returnTo` parameter

### Redirecting the user after authentication

The `returnTo` parameter can be appended to the login to specify where you would like to redirect the user after they have completed their authentication and have returned to your application.

For example: `/auth/login?returnTo=/dashboard` would redirect the user to the `/dashboard` route after they have authenticated.

### Redirecting the user after logging out

The `returnTo` parameter can be appended to the logout to specify where you would like to redirect the user after they have logged out.

For example: `/auth/login?returnTo=https://example.com/some-page` would redirect the user to the `https://example.com/some-page` URL after they have logged out.

> [!NOTE]
> The URLs specified as `returnTo` parameters must be registered in your client's **Allowed Logout URLs**.
## Accessing the authenticated user

### In the browser
Expand Down Expand Up @@ -405,6 +422,35 @@ To use Back-Channel Logout, you will need to provide a session store implementat

A `LogoutToken` object will be passed as the parameter to `deleteByLogoutToken` which will contain either a `sid` claim, a `sub` claim, or both.

## Combining middleware

By default, the middleware does not protect any pages. It is used to mount the authentication routes and provide the necessary functionality for rolling sessions.

You can combine multiple middleware, like so:

```ts
export async function middleware(request: NextRequest) {
const authResponse = await auth0.middleware(request)

// if path starts with /auth, let the auth middleware handle it
if (request.nextUrl.pathname.startsWith("/auth")) {
return authResponse
}

// call any other middleware here
const someOtherResponse = await someOtherMiddleware(request)

// add any headers from the auth middleware to the response
for (const [key, value] of authResponse.headers) {
someOtherResponse.headers.set(key, value)
}

return someOtherResponse
}
```

For a complete example using `next-intl` middleware, please see the `examples/` directory of this repository.

## Routes

The SDK mounts 6 routes:
Expand Down
3 changes: 3 additions & 0 deletions examples/with-next-intl/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["next/core-web-vitals", "next/typescript"]
}
40 changes: 40 additions & 0 deletions examples/with-next-intl/.gitignore
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
36 changes: 36 additions & 0 deletions examples/with-next-intl/README.md
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.
13 changes: 13 additions & 0 deletions examples/with-next-intl/app/[locale]/about/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Link } from "@/src/i18n/routing"
import { useTranslations } from "next-intl"

export default function AboutPage() {
const t = useTranslations("AboutPage")

return (
<div>
<h1>{t("title")}</h1>
<Link href="/">{t("home")}</Link>
</div>
)
}
28 changes: 28 additions & 0 deletions examples/with-next-intl/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { notFound } from "next/navigation"
import { routing } from "@/src/i18n/routing"
import { NextIntlClientProvider } from "next-intl"
import { getMessages } from "next-intl/server"

export default async function LocaleLayout({
children,
params,
}: {
children: React.ReactNode
params: Promise<{ locale: string }>
}) {
const { locale } = await params
// Ensure that the incoming `locale` is valid
if (!routing.locales.includes(locale as any)) {
notFound()
}

// Providing all messages to the client
// side is the easiest way to get started
const messages = await getMessages()

return (
<NextIntlClientProvider messages={messages}>
{children}
</NextIntlClientProvider>
)
}
13 changes: 13 additions & 0 deletions examples/with-next-intl/app/[locale]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Link } from "@/src/i18n/routing"
import { useTranslations } from "next-intl"

export default function HomePage() {
const t = useTranslations("HomePage")

return (
<div>
<h1>{t("title")}</h1>
<Link href="/about">{t("about")}</Link>
</div>
)
}
Binary file added examples/with-next-intl/app/favicon.ico
Binary file not shown.
Binary file not shown.
Binary file added examples/with-next-intl/app/fonts/GeistVF.woff
Binary file not shown.
21 changes: 21 additions & 0 deletions examples/with-next-intl/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
--background: #ffffff;
--foreground: #171717;
}

@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}

body {
color: var(--foreground);
background: var(--background);
font-family: Arial, Helvetica, sans-serif;
}
35 changes: 35 additions & 0 deletions examples/with-next-intl/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { Metadata } from "next";
import localFont from "next/font/local";
import "./globals.css";

const geistSans = localFont({
src: "./fonts/GeistVF.woff",
variable: "--font-geist-sans",
weight: "100 900",
});
const geistMono = localFont({
src: "./fonts/GeistMonoVF.woff",
variable: "--font-geist-mono",
weight: "100 900",
});

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
{children}
</body>
</html>
);
}
101 changes: 101 additions & 0 deletions examples/with-next-intl/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import Image from "next/image";

export default function Home() {
return (
<div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]">
<main className="flex flex-col gap-8 row-start-2 items-center sm:items-start">
<Image
className="dark:invert"
src="/next.svg"
alt="Next.js logo"
width={180}
height={38}
priority
/>
<ol className="list-inside list-decimal text-sm text-center sm:text-left font-[family-name:var(--font-geist-mono)]">
<li className="mb-2">
Get started by editing{" "}
<code className="bg-black/[.05] dark:bg-white/[.06] px-1 py-0.5 rounded font-semibold">
app/page.tsx
</code>
.
</li>
<li>Save and see your changes instantly.</li>
</ol>

<div className="flex gap-4 items-center flex-col sm:flex-row">
<a
className="rounded-full border border-solid border-transparent transition-colors flex items-center justify-center bg-foreground text-background gap-2 hover:bg-[#383838] dark:hover:bg-[#ccc] text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5"
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
className="dark:invert"
src="/vercel.svg"
alt="Vercel logomark"
width={20}
height={20}
/>
Deploy now
</a>
<a
className="rounded-full border border-solid border-black/[.08] dark:border-white/[.145] transition-colors flex items-center justify-center hover:bg-[#f2f2f2] dark:hover:bg-[#1a1a1a] hover:border-transparent text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 sm:min-w-44"
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Read our docs
</a>
</div>
</main>
<footer className="row-start-3 flex gap-6 flex-wrap items-center justify-center">
<a
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="/file.svg"
alt="File icon"
width={16}
height={16}
/>
Learn
</a>
<a
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="/window.svg"
alt="Window icon"
width={16}
height={16}
/>
Examples
</a>
<a
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
href="https://nextjs.org?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="/globe.svg"
alt="Globe icon"
width={16}
height={16}
/>
Go to nextjs.org →
</a>
</footer>
</div>
);
}
3 changes: 3 additions & 0 deletions examples/with-next-intl/lib/auth0.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Auth0Client } from "@auth0/nextjs-auth0/server"

export const auth0 = new Auth0Client()
10 changes: 10 additions & 0 deletions examples/with-next-intl/messages/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"HomePage": {
"title": "Hallo Welt!",
"about": "Zur Infoseite"
},
"AboutPage": {
"title": "Über Uns",
"home": "Zur Startseite"
}
}
10 changes: 10 additions & 0 deletions examples/with-next-intl/messages/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"HomePage": {
"title": "Hello world!",
"about": "Go to the about page"
},
"AboutPage": {
"title": "About Us",
"home": "Go to the home page"
}
}
Loading

0 comments on commit 18da6fb

Please sign in to comment.