@serafort/nuxt
v0.1.0
Published
Nuxt 3 module for Serafort B2B authentication, reactive composables (useUser, useSerafort), and Nitro server guards.
Readme
@serafort/nuxt
Nuxt 3 module for Serafort B2B authentication, reactive composables (useUser, useAuth), and Nitro server guards (requireUserSession).
Installation
npm install @serafort/nuxt @serafort/coreSetup
Add @serafort/nuxt to your nuxt.config.ts:
export default defineNuxtConfig({
modules: ['@serafort/nuxt'],
serafort: {
endpoint: process.env.NUXT_PUBLIC_SERAFORT_ENDPOINT,
cookieName: '__serafort_token',
loginUrl: '/login',
},
});Usage
In Vue Components / Pages
<script setup lang="ts">
const { user, isAuthenticated, hasPermission } = useAuth();
</script>
<template>
<div v-if="isAuthenticated">
<p>Welcome, {{ user?.userId }} (Tenant: {{ user?.tenantId }})</p>
<button v-if="hasPermission('org:write')">Create Organization</button>
</div>
<div v-else>
<NuxtLink to="/login">Sign In</NuxtLink>
</div>
</template>In Server Route Handlers (server/api/*)
// server/api/projects.get.ts
export default defineEventHandler(async (event) => {
// Requires authenticated session with permission
const user = await requireUserSession(event, {
permissions: ['projects:read'],
});
return {
tenantId: user.tenantId,
projects: ['Project Alpha', 'Project Beta'],
};
});Contributing
Before committing, changes are checked with pnpm run type-check. This is
wired up two ways — pick whichever fits your setup:
- Husky (npm-idiomatic, default for contributors who run
pnpm install): thepreparescript installs a Husky hook automatically, so once you've runpnpm installin a git checkout,git commitruns the check for you. .githooks/(portable, no Husky/Node required to install): rungit config core.hooksPath .githooksonce to point git directly at the checked-in.githooks/pre-commitscript, which runs the same check.
Both hooks run the same command, so pick one — you don't need both active at once.
CI (.github/workflows/ci.yml) runs type-check, test, and build on
every push to main and on every pull request.
