mirror of
https://github.com/SrIzan10/next-auth.git
synced 2026-05-01 10:55:20 +00:00
* chore: dev -> dev/nextjs * chore: move to /examples * chore: move to playgrounds, add dev/sveltekit * Update sync.yml * chore: dev scripts
The example repository is maintained from a monorepo. Pull Requests should be opened against
nextauthjs/next-auth.
Nuxt 3 support with Auth.js is currently experimental. This directory contains a minimal, proof-of-concept application. Parts of this is expected to be abstracted away into a package like @auth/nuxt.
Getting Started
- Setup your environment variables in
nuxt.config.ts:
export default defineNuxtConfig({
// https://v3.nuxtjs.org/migration/runtime-config#runtime-config
runtimeConfig: {
secret: process.env.NEXTAUTH_SECRET
github: {
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET
}
}
})
- Set up Auth.js options
Go to the API handler file (server/api/auth/[...].ts) and setup your providers. This file contains the dynamic route handler for Auth.js which will also contain all of your global Auth.js configurations.
Here's an example of what it looks like:
// server/api/auth/[...].ts
import { NuxtAuthHandler } from "@/lib/auth/server"
import GithubProvider from "@auth/core/providers/github"
import type { AuthOptions } from "@auth/core"
const runtimeConfig = useRuntimeConfig()
export const authOptions: AuthOptions = {
secret: runtimeConfig.secret,
providers: [
GithubProvider({
clientId: runtimeConfig.github.clientId,
clientSecret: runtimeConfig.github.clientSecret,
}),
],
}
export default NuxtAuthHandler(authOptions)
All requests to /api/auth/* (signIn, callback, signOut, etc.) will automatically be handled by Auth.js.