@authon/nuxt
Nuxt 3 module for Authon — auto-imported composables, components, and server middleware.
Install
npm install @authon/nuxt
pnpm add @authon/nuxt
Requires nuxt >= 3.0.0.
Quick Start
1. Add Module
export default defineNuxtConfig({
modules: ['@authon/nuxt'],
authon: {
publishableKey: process.env.NUXT_PUBLIC_AUTHON_KEY,
},
});
2. Use in Pages
All composables and components are auto-imported:
<!-- pages/index.vue -->
<template>
<div>
<SignedIn>
<UserButton />
<p>Welcome, {{ user?.displayName }}</p>
</SignedIn>
<SignedOut>
<button @click="openSignIn()">Sign In</button>
</SignedOut>
</div>
</template>
<script setup>
const { user, openSignIn } = useAuthon();
</script>
3. Server-side
export default defineEventHandler(async (event) => {
const user = await requireAuthonUser(event);
return { user };
});
API Reference
Module Options
authon: {
publishableKey: string;
secretKey?: string;
apiUrl?: string;
publicRoutes?: string[];
}
Auto-imported Composables
useAuthon() | Full auth state and actions |
useUser() | Current user and loading state |
Auto-imported Components
<SignedIn> | Renders slot only when signed in |
<SignedOut> | Renders slot only when signed out |
<UserButton> | Avatar dropdown with sign-out |
<Protect> | Conditional rendering with fallback slot |
Server Utilities
requireAuthonUser(event) | Get and verify the current user (throws 401 if unauthenticated) |
getAuthonUser(event) | Get the current user or null |
Documentation
authon.dev/docs
License
MIT