nest-phylax
Version:
Security library for NestJS
47 lines (46 loc) • 1.42 kB
TypeScript
import { Type } from '@nestjs/common';
import { ClaimsDto } from '../jwt-auth/';
export type Request = {
headers: {
authorization: string;
};
claims: ClaimsDto;
};
export declare class Jwt {
value: string;
sub: string | number;
jti?: string;
role: string;
}
export declare class JwtDatabaseModel {
jti: string;
exp: string;
sub: string;
}
export type RefreshTokenRecord = Omit<ClaimsDto, 'role'>;
export interface User {
id: string;
password?: string;
getUsername(): string;
getRefreshTokens?(): Jwt[];
}
export interface UserRepository {
findOneById(id: string | number): Promise<User>;
saveRefreshToken(refreshToken: Jwt, userId: string): Promise<void>;
getUserRole(user: User): Promise<string>;
findUserByUsername(username: string): Promise<User>;
}
export interface PasswordEncoder {
encode(password: string): Promise<string>;
compare(password: string, encodedPassword: string): Promise<boolean>;
}
export type NestPhylaxProvider<T = any> = NestPhylaxClassProvider<T> | NestPhylaxValueProvider<T> | NestPhylaxFactoryProvider<T>;
export interface NestPhylaxClassProvider<T = any> {
useClass: Type<T>;
}
export interface NestPhylaxValueProvider<T = any> {
useValue: T;
}
export interface NestPhylaxFactoryProvider<T = any> {
useFactory: (...args: any[]) => T | Promise<T>;
}