Auth
Add sign-in and user sessions to your app with Better Auth, set up from one server file.
server/auth.ts
import { defineAuth } from 'vite-hub/auth'
// Sign-up, sign-in, and session routes
// appear under /api/auth.
export default defineAuth({
appName: 'Acme',
emailAndPassword: { enabled: true },
access: {
// Requests to these APIs need a session
routes: ['/api/admin/**'],
},
})One file sets up sign-in
Add
server/auth.ts to get sign-up, sign-in, and session routes under /api/auth.Protect a Nuxt page
Set
definePageMeta({ auth: 'user' }) to send signed-out visitors to the login page.Session state in Vue
useUserSession() gives you the user, loggedIn, and sign-in and sign-out helpers.