@lygos/nestjs-better-auth
Version:
Better Auth for NestJS
26 lines • 1.17 kB
TypeScript
import type { CanActivate, ExecutionContext } from "@nestjs/common";
import { Reflector } from "@nestjs/core";
import type { Auth } from "better-auth";
import { type getSession } from "better-auth/api";
/**
* Type representing a valid user session after authentication
* Excludes null and undefined values from the session return type
*/
export type UserSession = NonNullable<Awaited<ReturnType<ReturnType<typeof getSession>>>>;
/**
* NestJS guard that handles authentication for protected routes
* Can be configured with @Public() or @Optional() decorators to modify authentication behavior
*/
export declare class AuthGuard implements CanActivate {
private readonly reflector;
private readonly auth;
constructor(reflector: Reflector, auth: Auth);
/**
* Validates if the current request is authenticated
* Attaches session and user information to the request object
* @param context - The execution context of the current request
* @returns True if the request is authorized to proceed, throws an error otherwise
*/
canActivate(context: ExecutionContext): Promise<boolean>;
}
//# sourceMappingURL=auth-guard.d.ts.map