Shared authentication utilities for Node.js and Next.js applications.
pnpm add @cortex-shared/auth- JWT token generation and verification
- Password hashing and verification
- Email and password validation
- Password strength checker
import { generateToken, verifyToken } from '@cortex-shared/auth';
const secret = 'your-secret-key';
const payload = { id: '123', email: 'user@example.com' };
// Generate token
const token = generateToken(payload, secret);
// Verify token
const decoded = verifyToken(token, secret);import { hashPassword, verifyPassword } from '@cortex-shared/auth';
// Hash password
const hash = await hashPassword('myPassword123!');
// Verify password
const isMatch = await verifyPassword('myPassword123!', hash);import {
isValidEmail,
isStrongPassword,
getPasswordStrengthFeedback,
sanitizeEmail,
} from '@cortex-shared/auth';
// Validate email
if (isValidEmail('user@example.com')) {
const sanitized = sanitizeEmail(' User@Example.com ');
// 'user@example.com'
}
// Check password strength
if (isStrongPassword('MyPassword123!')) {
const feedback = getPasswordStrengthFeedback('weak');
// { score: 1, feedback: [...] }
}pnpm dev # Watch mode
pnpm build # Build
pnpm lint # Lint
pnpm type-check # Type check