nuxt-auth
is a feature-packed, open-source authentication module for Nuxt 3 applications.
npm i -D @sidebase/nuxt-auth
Then visit the Quick Start documentation to setup the module.
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). Features of nuxt-auth
include:
- βοΈ Authentication providers:
- βοΈ OAuth (e.g., Github, Google, Twitter, Azure, ...)
- βοΈ Custom OAuth (write it yourself)
- βοΈ Credentials (password + username)
- βοΈ Email Magic URLs
- βοΈ Isomorphic / Universal Auth Composable
useAuth
supports:- actions:
getSession
,getCsrfToken
,getProviders
,signIn
,signOut
- getters:
status
,data
,lastRefreshedAt
- full typescript support for all methods and property
- actions:
- βοΈ Application-side middleware protection
- βοΈ Server-side middleware and endpoint protection
- βοΈ Advanced features for session life-cycle management:
- Refresh the session periodically
- Refresh the session on tab-refocus
- One time session fetch on page load, afterwards for specific actions (e.g., on navigation)
- π§ Session broadcasting between tabs (see #70)
- βοΈ Persistent sessions across requests
- βοΈ REST API:
GET /signin
,POST /signin/:provider
,GET/POST /callback/:provider
,GET /signout
,POST /signout
,GET /session
,GET /csrf
,GET /providers
Visit the nuxt-auth
demo page here:
You can find the demo source-code here.
This project uses pnpm
for development.
- Run
pnpm dev:prepare
to generate type stubs. - Use
pnpm dev
to start the module playground in development mode. - Run
pnpm lint
to run eslint - Run
pnpm typecheck
to run typescheck via tsc - Run
pnpm publish --access public
to publish (bump version before)
This module also has it's own playground:
> git clone https://github.com/sidebase/nuxt-auth
> cd nuxt-auth
# **OPEN THE `~/playground/server/api/auth/[...].ts` and configure your own auth-provider
> pnpm i
> pnpm dev:prepare
> pnpm dev
# -> open http://localhost:3000