Auth-vir is a JavaScript/TypeScript library designed to simplify and secure authentication mechanisms in web applications. It provides robust features for handling JWT (JSON Web Token) based session cookies, CSRF (Cross-Site Request Forgery) protection through tokens, and secure password hashing. The library is actively maintained, with the current stable version being 5.2.0. Releases typically follow a semantic versioning approach, with minor and patch updates occurring every few weeks to months, and major versions introducing breaking changes less frequently, as observed from recent release history. Its key differentiators include a focus on security best practices out-of-the-box, offering both backend and frontend client implementations, and explicit support for ESM (ECMAScript Modules) and browser environments, ensuring modern application compatibility. It aims to abstract away common auth complexities while maintaining high security standards.
npm install auth-virVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates setting up a basic Node.js server using auth-vir for user login, generating secure JWT and CSRF tokens, and authenticating subsequent requests. It shows password hashing, token generation, and user ID extraction from request headers.
Ensure your backend extracts the raw CSRF token directly from the 'csrf-token' cookie header (or custom header name) and that your frontend client correctly sends this token. Refer to the updated `extractUserIdFromRequestHeaders` usage.
If upgrading from an earlier v3.x version, be aware that v4.0.0 changed the CSRF token format to raw. If upgrading from v4.x to v5.x, refer to the v5.0.0 warning for cookie-only storage.
Store JWT keys in environment variables, a secure vault, or a dedicated secrets management service. Load them at runtime and ensure they are never logged or exposed in client-side code.
Configure your server's CORS policy to include `AuthHeaderName.CsrfToken` in `Access-Control-Allow-Headers` and specify the exact origin(s) for `Access-Control-Allow-Origin`.
Ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`) or use dynamic `import()` if you must use it within a CommonJS context. Always use `import ... from 'auth-vir'` syntax.
Refactor your code to use ESM equivalents (e.g., `import.meta.url` for path resolution) or ensure your environment is configured for ESM.
Verify that the output from `generateNewJwtKeys()` is stored verbatim and loaded without corruption. Ensure no whitespace or malformation occurs during storage/retrieval from environment variables or secret managers.
Ensure your frontend is correctly extracting the CSRF token from the initial login response (e.g., from the `Set-Cookie` header if `AuthCookie.CsrfToken` is used) and sending it back in subsequent requests via the `csrf-token` header. Check CORS configuration.
Consult the `auth-vir` documentation for the correct named exports. Check for potential default exports or specific versions where the symbol might have existed under a different name or export style.
No dependency data recorded yet.