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