UNPKG

@lygos/nestjs-better-auth

Version:
45 lines 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Hook = exports.AfterHook = exports.BeforeHook = exports.Session = exports.Optional = exports.Public = void 0; const common_1 = require("@nestjs/common"); const symbols_1 = require("./symbols"); /** * Marks a route or a controller as public, allowing unauthenticated access. * When applied, the AuthGuard will skip authentication checks. */ const Public = () => (0, common_1.SetMetadata)("PUBLIC", true); exports.Public = Public; /** * Marks a route or a controller as having optional authentication. * When applied, the AuthGuard will allow the request to proceed * even if no session is present. */ const Optional = () => (0, common_1.SetMetadata)("OPTIONAL", true); exports.Optional = Optional; /** * Parameter decorator that extracts the user session from the request. * Provides easy access to the authenticated user's session data in controller methods. */ exports.Session = (0, common_1.createParamDecorator)((_data, context) => { const request = context.switchToHttp().getRequest(); return request.session; }); /** * Registers a method to be executed before a specific auth route is processed. * @param path - The auth route path that triggers this hook (must start with '/') */ const BeforeHook = (path) => (0, common_1.SetMetadata)(symbols_1.BEFORE_HOOK_KEY, path); exports.BeforeHook = BeforeHook; /** * Registers a method to be executed after a specific auth route is processed. * @param path - The auth route path that triggers this hook (must start with '/') */ const AfterHook = (path) => (0, common_1.SetMetadata)(symbols_1.AFTER_HOOK_KEY, path); exports.AfterHook = AfterHook; /** * Class decorator that marks a provider as containing hook methods. * Must be applied to classes that use BeforeHook or AfterHook decorators. */ const Hook = () => (0, common_1.SetMetadata)(symbols_1.HOOK_KEY, true); exports.Hook = Hook; //# sourceMappingURL=decorators.js.map