Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add example-app-router-with-next-auth-without-i18n-routing #1397

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-secret-key
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
env: {
node: true
},
extends: [
'molindo/typescript',
'molindo/react',
'molindo/tailwind',
'plugin:@next/next/recommended'
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/node_modules
/.next/
.DS_Store
tsconfig.tsbuildinfo
/test-results/
/playwright-report/
/playwright/.cache/
.env*
!.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Example App Router with next-auth Without i18n Routing

This example demonstrates how an application can use a locale defined in the `i18n.ts` file for `next-intl` in an App Router setup ([without i18n routing](https://next-intl-docs.vercel.app/docs/getting-started/app-router/without-i18n-routing)) with `next-auth` integration.

This application uses Server Actions in one place:

1. **Locale Management**: The locale is stored in a cookie and can be updated using the `setUserLocale` function in [`src/services/locale.ts`](./src/services/locale.ts).

User authentication is handled using `next-auth`.

## Run Your Own Instance

### Locally

To run this project locally, follow these steps:

1. **Install dependencies:**

```bash
npm install
```

2. **Create a `.env.local` file:**

In the root directory of the project, create a file named `.env.local` and add the following environment variables:

```env
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-secret-key
```

- **Note:** Replace `your-secret-key` with your own secret key. You can generate it using the command:

```bash
openssl rand -base64 32
```

- If you are using a different port for your local server (e.g., `3002`), change `NEXTAUTH_URL` to the appropriate address:

```env
NEXTAUTH_URL=http://localhost:3002
```

3. **Start the development server:**

```bash
npm run dev
```

4. **Open the application in your browser:**

Navigate to [http://localhost:3000](http://localhost:3000) (or the port you specified) in your browser.

5. **Log in:**

Use the following credentials to log in:

- **Username:** `admin`
- **Password:** `admin`

### Deploying to Vercel

By deploying the application to [Vercel](https://vercel.com), you can see the example in action. Note that during the process, you will be prompted to create a new GitHub repository, allowing you to make further changes.

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/amannn/next-intl/tree/main/examples/example-app-router-without-i18n-routing)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"RootLayout": {
"title": "Beispiel für next-intl mit Auth.js ohne i18n-Routing"
},
"AppLayout": {
"home": "Startseite",
"logout": "Abmelden",
"profile": "Profil"
},
"HomePage": {
"welcome": "Willkommen, {name}!"
},
"LocaleSwitcher": {
"de": "Deutsch",
"en": "Englisch",
"label": "Sprache"
},
"LoginPage": {
"credentials": "Benutzername: admin / Passwort: admin",
"login": "Anmelden",
"password": "Passwort",
"title": "Willkommen zurück",
"username": "Benutzername"
},
"ProfilePage": {
"title": "Profil"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"RootLayout": {
"title": "Example of next-intl with Auth.js without i18n routing"
},
"AppLayout": {
"home": "Home",
"logout": "Logout",
"profile": "Profile"
},
"HomePage": {
"welcome": "Welcome, {name}!"
},
"LocaleSwitcher": {
"de": "German",
"en": "English",
"label": "Language"
},
"LoginPage": {
"credentials": "Username: admin / Password: admin",
"login": "Log In",
"password": "Password",
"title": "Welcome back",
"username": "Username"
},
"ProfilePage": {
"title": "Profile"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// middleware.ts
export { default } from 'next-auth/middleware';

export const config = {
matcher: ['/((?!login|api/auth).*)'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const withNextIntl = require('next-intl/plugin')();

module.exports = withNextIntl();
Loading
Loading