authrix
Version:
Lightweight, flexible authentication library for Node.js and TypeScript.
83 lines (78 loc) • 3.56 kB
TypeScript
export { a as authConfig, g as getAuthrixStatus, i as initAuth, b as isAuthrixInitialized } from './index-2c4aN9k6.js';
import { requireAuth } from './core.barrel.js';
import { Request, Response, NextFunction } from 'express';
export { g as generateSecurePassword, h as hashPassword, n as needsRehash, b as validatePassword, a as verifyAndCheckRehash, v as verifyPassword } from './hash-D54ZxOVU.js';
export { c as createLogger, l as logger, r as reconfigureLogger } from './logger-BkCgRz6A.js';
export { A as AuthDbAdapter, a as AuthUser } from './db-BIgxMgj8.js';
export { T as TokenPayload } from './verifyToken-CAoFBIjp.js';
import { a as LogoutOptions, L as LogoutResult, S as SessionUser, l as logoutCore } from './session-C-ESV9uK.js';
import { S as SignupOptions, b as SignupResult, c as SigninOptions, d as SigninResult, s as signupCore, a as signinCore } from './signin-D81G4lNe.js';
interface AuthenticatedRequest extends Request {
user?: {
id: string;
email: string;
createdAt?: Date;
};
}
declare function authMiddleware(req: AuthenticatedRequest, res: Response, next: NextFunction): Promise<void>;
interface ActionContext {
res?: any;
req?: any;
}
interface AuthActionResult<TUser> {
user: TUser;
token?: string;
meta?: Record<string, any>;
}
declare function performSignup(email: string, password: string, options?: SignupOptions, ctx?: ActionContext): Promise<AuthActionResult<SignupResult['user']>>;
declare function performSignin(email: string, password: string, options?: SigninOptions, ctx?: ActionContext): Promise<AuthActionResult<SigninResult['user']>>;
declare function performLogout(options?: LogoutOptions, ctx?: ActionContext): Promise<LogoutResult>;
declare function getUser(ctx?: ActionContext): Promise<SessionUser | null>;
declare function isAuthed(ctx?: ActionContext): Promise<boolean>;
declare function middlewareOptional(handler: any): (req: any, res: any) => Promise<any>;
declare function middlewareWithUser(handler: any): (req: any, res: any) => Promise<any>;
declare const auth: {
readonly actions: {
readonly signup: typeof performSignup;
readonly signin: typeof performSignin;
readonly logout: typeof performLogout;
};
readonly session: {
readonly getUser: typeof getUser;
readonly isAuthenticated: typeof isAuthed;
};
readonly middleware: {
require: typeof requireAuth;
guard: typeof requireAuth;
optional: typeof middlewareOptional;
withUser: typeof middlewareWithUser;
};
readonly handlers: {
signup: () => Promise<any>;
signin: () => Promise<any>;
logout: () => Promise<any>;
currentUser: () => Promise<any>;
validateToken: () => Promise<any>;
};
readonly cookies: {
create: (token: string, opts?: any) => string;
clear: () => string;
};
readonly env: {
detect: () => {
isNextJs: boolean;
};
next(): Promise<{
info: any;
infoAsync: any;
reset: any;
redetect: any;
injectTest: any;
} | null>;
};
};
type AuthNamespace = typeof auth;
declare const signupCoreDeprecated: typeof signupCore;
declare const signinCoreDeprecated: typeof signinCore;
declare const logoutCoreDeprecated: typeof logoutCore;
export { type AuthActionResult, type AuthNamespace, type AuthenticatedRequest, auth, authMiddleware, logoutCoreDeprecated, requireAuth, signinCoreDeprecated, signupCoreDeprecated };