auth-token-cookie
raw JSON → 0.0.5 verified Sat Apr 25 auth: no javascript deprecated
Seneca.js internal plugin for persisting authentication tokens in cookies. Version 0.0.5 is the latest stable release (last published 2016). This module is auto-loaded by seneca-auth and requires Seneca 0.8–0.9. It is not maintained for modern Seneca versions (3.x+). Key differentiator: minimal configuration, designed as a drop-in for seneca-auth's cookie-based token storage.
Common errors
error Error: Cannot find module 'auth-token-cookie' ↓
cause The package is not installed as a direct dependency, but seneca-auth requires it.
fix
Ensure auth-token-cookie is in node_modules; it's usually installed as a dependency of seneca-auth.
error TypeError: seneca.use is not a function ↓
cause Using ES module import syntax for a CJS-only package.
fix
Use require() instead of import.
error Error: Plugin 'auth-token-cookie' is already registered ↓
cause Manually calling seneca.use('auth-token-cookie') when it is auto-loaded by seneca-auth.
fix
Remove the explicit use() call.
Warnings
deprecated auth-token-cookie is no longer maintained for Seneca 3.x+. ↓
fix Use seneca-auth's built-in cookie handling or a modern auth solution like @seneca/auth.
breaking Only compatible with Seneca 0.8–0.9 and Node.js 4–5. ↓
fix Upgrade to Seneca 3.x and use @seneca/auth with its own cookie plugin.
gotcha The plugin is auto-loaded by seneca-auth; manual registration is not required. ↓
fix Do not call seneca.use('auth-token-cookie') explicitly. It's loaded by seneca.use('auth').
gotcha No ESM exports; only CommonJS require() works. ↓
fix Use require('auth-token-cookie') or import via createRequire.
deprecated The package has not been updated since 2016 and lacks modern security features. ↓
fix Consider alternatives like cookie-based JWT tokens with express or @fastify/cookie.
Install
npm install auth-token-cookie yarn add auth-token-cookie pnpm add auth-token-cookie Imports
- default (plugin) wrong
import authTokenCookie from 'auth-token-cookie'correctconst authTokenCookie = require('auth-token-cookie') - plugin registration wrong
seneca.use(require('auth-token-cookie').default)correctseneca.use('auth-token-cookie') - options wrong
seneca.use('auth-token-cookie', { cookieName: 'myapp_token' })correctseneca.use('auth', { token: { cookie: { name: 'myapp_token' } } })
Quickstart
const Seneca = require('seneca')
const seneca = Seneca()
// The auth-token-cookie plugin is auto-loaded by seneca-auth
seneca.use('seneca-auth')
// Configure auth token cookie
seneca.use('auth', {
token: {
cookie: {
name: 'token',
secret: process.env.COOKIE_SECRET ?? ''
}
}
})
// Example: register an action that requires authentication
seneca.add({ role: 'user', cmd: 'profile' }, function (msg, done) {
var user = this.context.msg$?.meta?.user
done(null, { user: user })
})
// Start listening (optional)
seneca.listen({ type: 'http', port: 3000 })