Nuxt user authentication and sessions via NextAuth.js.
nuxt-auth
wraps NextAuth.js to offer the reliability & convenience of a 12k star library to the nuxt 3 ecosystem with a native developer experience (DX).
Quick Start
- Install the package:
npm i -D @sidebase/nuxt-auth
- Add the package to your
nuxt.config.ts
:export default defineNuxtConfig({ modules: ['@sidebase/nuxt-auth'], })
- Done! You can now use all user-related functionality, for example:
- client-side (e.g., from
.vue
files):const { status, data, signIn, signOut, } = await useSession({ // Whether a session is required. If it is, a redirect to the signin page will happen if no active session exists required: true }) // Session status: `unauthenticated`, `loading`, `authenticated` status.value // Session data, e.g., expiration, user.email, ... data.value // Start the unbranded sign-in flow await signIn() // Logout the user await signOut()
- client-side (e.g., from
Full Changelog: https://github.com/sidebase/nuxt-auth/commits/0.0.1-beta.1