Skip to main content

Create Server Authorization


Creates the Authorization directory with the selected strategy (basic/JWT)

Event Name


Event Params

export interface CreateServerAuthParams extends EventParams {
srcDir: string;


The target directory the auth folder will be generated in

Example In order to set the auth strategy, we should use the before lifecycle event and call the skipDefaultBehavior util. As a result, the default event won't run, but we would have to provide our logic in the after lifecycle event:

  • the path to our static auth folder
  • the path in which we want the auth folder to be generated in
context: DsgContext,
eventParams: CreateAuthModulesParams
) {
context.utils.skipDefaultBehavior = true;
return eventParams;

async afterCreateServerAuth(
context: DsgContext,
eventParams: CreateAuthModulesParams,
modules: ModuleMap
) {
const staticPath = resolve(__dirname, "../static");
const staticsFiles = await context.utils.importStaticModules(

return modules;

auth-basic plugin:

auth-jwt plugin:

For example, you can see the diff on defaultAuth.guard.ts after the auth-basic plugin was installed on a newly generated app that uses the JWT approach:

- export class DefaultAuthGuard extends BasicAuthGuard {
+ export class DefaultAuthGuard extends JwtAuthGuard
constructor(private readonly reflector: Reflector) {