Registry / security / authey

authey

JSON →
library0.8.3jsnpmunverified

Expose Auth.js (formerly NextAuth.js) REST APIs (sign in, sign out, session, providers, CSRF token) to any connect-compatible Node.js framework like Express, Fastify, or Nuxt (via h3). Current stable version 0.8.3. Active development. Key differentiator: decouples Auth.js from Next.js, enabling authentication in non-Next.js apps using the same Auth.js providers and configuration. Requires @auth/core >=0.10.0 as peer dependency. Ships TypeScript types.

npm install authey
INSTALL
IMPORT
SIG · AUTHEY
A
authey
securityjavascriptv0.8.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createAuthMiddleware
import { createAuthMiddleware } from 'authey'
import createAuthMiddleware from 'authey'
Default export does not exist in authey; must use named import.
createAuthMiddleware
import { createAuthMiddleware } from 'authey'
const createAuthMiddleware = require('authey')
Package is ESM-only; CommonJS require will not work.
AuthConfig (type)
import type { AuthConfig } from '@auth/core'
import { AuthConfig } from 'authey'
AuthConfig type is not re-exported from authey; import from @auth/core.

Sets up an Express app with Auth.js authentication middleware using Google OAuth provider.

import express from 'express'; import { createAuthMiddleware } from 'authey'; import type { AuthConfig } from '@auth/core'; import GoogleProvider from '@auth/core/providers/google'; const app = express(); const authConfig: AuthConfig = { secret: process.env.AUTH_SECRET ?? '', trustHost: Boolean(process.env.AUTH_TRUST_HOST), providers: [ GoogleProvider({ clientId: process.env.GOOGLE_ID ?? '', clientSecret: process.env.GOOGLE_SECRET ?? '', }), ], }; app.use(createAuthMiddleware(authConfig)); app.listen(3000, () => console.log('Server running on port 3000'));
Debug
Known issues
gotchacreateAuthMiddleware must be used as an Express middleware and expects connect-compatible frameworks. Fastify requires @fastify/middie to wrap middleware.
fix
For Fastify, register @fastify/middie and call fastify.use(). For Nuxt, wrap with fromNodeMiddleware from h3.
affects: >=0.1.0
deprecatedAuth.js (formerly NextAuth.js) v5 renamed some provider options. Using older provider options may cause issues.
fix
Refer to Auth.js v5 documentation and ensure provider config matches the version of @auth/core installed.
affects: >=0.8.0
gotchaThe middleware does not include a default error handler; unhandled errors may crash the server.
fix
Wrap app.use() in a try-catch or add a global error handler for Express.
affects: >=0.1.0
gotchaThe middleware internally uses Auth.js REST endpoints, which require a valid secret and trustHost setting in production.
fix
Set AUTH_SECRET (generate using https://generate-secret.vercel.app/32) and AUTH_TRUST_HOST=true in production.
affects: >=0.1.0
breakingBreaking change in @auth/core 0.10+: The imported provider names now use PascalCase (e.g., GoogleProvider, EmailProvider). Older camelCase names (e.g., google, email) are deprecated.
fix
Update provider imports to PascalCase: import GoogleProvider from '@auth/core/providers/google'.
affects: >=0.10.0
Errors
Common errors & fixes
ERR_MODULE_NOT_FOUND: Cannot find package '@auth/core'
@auth/core is a peer dependency and must be installed explicitly.
fix
Run: npm install @auth/core
TypeError: createAuthMiddleware is not a function
Default import used instead of named import.
fix
Use: import { createAuthMiddleware } from 'authey'
Error: connect() requires a middleware function
createAuthMiddleware was called without passing a config object or used incorrectly on non-connect framework.
fix
Ensure you pass the auth config object and use it with app.use() in Express.
TypeError: Cannot read properties of undefined (reading 'providers')
authConfig object is missing providers array or is undefined.
fix
Provide a valid AuthConfig object with a providers array: const authConfig: AuthConfig = { providers: [...], secret: '...', trustHost: true }
Upgrade
Version history
0.8.3latest on npm
Audit
Dependencies
@auth/corerequiredPeer dependency required to provide Auth.js core functionality and provider implementations.
Agent activity
25 hits · last 30 days
node
24
OpenAI (training)
1
Resources
packageauthey
authey — npm install authey · libregistry