# Nuxt.js

## [Overview](/content/docs/sdk-examples/nuxtjs#overview/index.html)

[Nuxt.js](https://nuxt.com/) is the intuitive [Vue.js](https://vuejs.org/) framework that enables you to create full-stack web applications with server-side rendering, file-based routing, and auto-imports. This example demonstrates how to integrate **Zitadel** using the **[OAuth 2.0 PKCE flow](https://oauth.net/2/pkce/)** to authenticate users securely and maintain sessions across your application.

#### [Auth library](/content/docs/sdk-examples/nuxtjs#auth-library/index.html)

This example uses **[@sidebase/nuxt-auth](https://www.npmjs.com/package/@sidebase/nuxt-auth)**, a Nuxt module that wraps **[NextAuth.js/Auth.js](https://next-auth.js.org/)** for seamless authentication integration. Under the hood, it leverages **[next-auth](https://www.npmjs.com/package/next-auth)** with the **[openid-client](https://www.npmjs.com/package/openid-client)** library to implement the [OpenID Connect (OIDC)](/content/docs/apis/openidoauth/endpoints/index.html) protocol, manage [PKCE](https://oauth.net/2/pkce/), perform token exchange, and handle [session management](https://authjs.dev/concepts/session-strategies).

* * *

## [What this example demonstrates](/content/docs/sdk-examples/nuxtjs#what-this-example-demonstrates/index.html)

This [Nuxt.js](https://nuxt.com/) application showcases a complete authentication pattern using [Zitadel](/content/docs/index.html) with the **[PKCE flow](https://oauth.net/2/pkce/)**. Users begin on a public landing page where they can initiate sign-in with Zitadel through the **[@sidebase/nuxt-auth](https://www.npmjs.com/package/@sidebase/nuxt-auth)** module. After successful authentication, they're redirected to a protected profile page displaying their [user information and claims](/content/docs/apis/openidoauth/claims/index.html).

The example implements secure [session management](https://authjs.dev/concepts/session-strategies) using [JWT tokens](/content/docs/apis/openidoauth/endpoints#token_endpoint/index.html) with automatic [token refresh](https://authjs.dev/concepts/session-strategies) capabilities through [refresh tokens](https://authjs.dev/concepts/session-strategies) using [JWT tokens](/content/docs/apis/openidoauth/endpoints#token-endpoint/index.html). Protected routes automatically redirect unauthenticated users to the sign-in flow using [Nuxt middleware](https://nuxt.com/docs/guide/directory-structure/middleware), ensuring sensitive areas remain secure. The application also includes complete **[federated logout](/content/docs/guides/integrate/login/oidc/logout/index.html)** functionality that properly terminates both the local session and the Zitadel session through the [end-session endpoint](https://authjs.dev/concepts/session-strategies).

* * *

## [Getting started](/content/docs/sdk-examples/nuxtjs#getting-started/index.html)

### [Prerequisites](/content/docs/sdk-examples/nuxtjs#prerequisites/index.html)

Before running this example, you need to create and configure a PKCE application in the [ZITADEL Management Console](/content/docs/guides/manage/console/console-overview/index.html). Follow the PKCE application setup guide to:

1. Create a new Web application in your [Zitadel project](/content/docs/guides/manage/console/projects-overview/index.html)
2. Configure it to use the PKCE authentication method
3. Set up your redirect URIs (e.g., `http://localhost:3000/api/auth/callback/zitadel` for development)
4. Configure post-logout redirect URIs (e.g., `http://localhost:3000`)
5. Copy your **Client ID** for use in the next steps

> **Note:** Make sure to enable **Dev Mode** in the ZITADEL Management Console if you're using HTTP URLs during local development. For production, always use HTTPS URLs and disable Dev Mode.

### [Run the example](/content/docs/sdk-examples/nuxtjs#run-the-example/index.html)

Once you have your Zitadel application configured:

1. Clone the [repository](https://github.com/zitadel/example-auth-nuxtjs).
2. Create a `.env` file and configure it with the values from your [Zitadel application](/content/docs/guides/manage/console/applications-overview/index.html). **Use these exact environment variable names:**

```
   PORT=3000
   SESSION_DURATION=3600
   NUXT_AUTH_SECRET=your-very-secret-and-strong-session-key
   ZITADEL_DOMAIN=https://your-zitadel-domain
   ZITADEL_CLIENT_ID=your-client-id
   ZITADEL_CLIENT_SECRET=your-randomly-generated-client-secret
   ZITADEL_CALLBACK_URL=http://localhost:3000/api/auth/callback/zitadel
   ZITADEL_POST_LOGOUT_URL=http://localhost:3000
   AUTH_ORIGIN=http://localhost:3000
```

Replace these values with:

- Your actual Zitadel instance URL (the **Issuer** from your [Zitadel instance settings](/content/docs/guides/manage/console/console-overview/index.html))
- The **Client ID** you copied when creating the application
- A randomly generated **NUXT_AUTH_SECRET** for session encryption (generate using: `node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"`)
- The **callback URI** you configured in the PKCE setup (must match exactly)
- The **post-logout redirect URI** you configured in the PKCE setup

3. Install dependencies using [npm](https://www.npmjs.com/) and start the development server:

```
   npm install
   npm run dev
```

The application will be running at `http://localhost:3000` where you can test the complete authentication flow.

* * *

## [Learn more and resources](/content/docs/sdk-examples/nuxtjs#learn-more-and-resources/index.html)

- [PKCE concept](https://oauth.net/2/pkce/)
- [Federated logout](/content/docs/guides/integrate/login/oidc/logout/index.html)
- [OIDC integration guide](/content/docs/guides/integrate/login/oidc/login-users/index.html)
- [Framework docs](https://nuxt.com/)
- [@sidebase/nuxt-auth](https://www.npmjs.com/package/@sidebase/nuxt-auth)
- [NextAuth.js/Auth.js](https://next-auth.js.org/)
- [Example repository](https://github.com/zitadel/example-auth-nuxtjs)
