com um clique
angular-guard
Generates Angular route guards for authentication and authorization
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Menu
Generates Angular route guards for authentication and authorization
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Baseado na classificação ocupacional SOC
Generates Angular animations for smooth UI transitions and interactions
Generates Angular components with best practices and patterns
Generates an Angular dialog component extending BaseDialogComponent
Generates Angular directives for DOM manipulation and behavior enhancement
Generates Angular error boundary components for graceful error handling
Generates an Angular feature component (Standalone, OnPush)
| name | angular-guard |
| description | Generates Angular route guards for authentication and authorization |
This skill helps you generate Angular route guards following best practices for authentication, authorization, and route protection.
import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { map, take } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class {{Name}}Guard implements CanActivate {
constructor(
private router: Router,
// private authService: AuthService
) {}
canActivate(): Observable<boolean> | Promise<boolean> | boolean {
// return this.authService.isAuthenticated$.pipe(
// take(1),
// map(isAuthenticated => {
// if (!isAuthenticated) {
// this.router.navigate(['/login']);
// return false;
// }
// return true;
// })
// );
// Temporary implementation
const isAuthenticated = localStorage.getItem('isAuthenticated') === 'true';
if (!isAuthenticated) {
this.router.navigate(['/login']);
return false;
}
return true;
}
}
import { Injectable } from '@angular/core';
import { CanActivateChild, Router } from '@angular/router';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class {{Name}}ChildGuard implements CanActivateChild {
constructor(
private router: Router,
// private authService: AuthService
) {}
canActivateChild(): Observable<boolean> | Promise<boolean> | boolean {
// Implement child route protection logic
return true;
}
}
import { Injectable } from '@angular/core';
import { CanDeactivate } from '@angular/router';
import { Observable } from 'rxjs';
export interface CanComponentDeactivate {
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
}
@Injectable({
providedIn: 'root'
})
export class {{Name}}DeactivateGuard implements CanDeactivate<CanComponentDeactivate> {
canDeactivate(component: CanComponentDeactivate): Observable<boolean> | Promise<boolean> | boolean {
return component.canDeactivate ? component.canDeactivate() : true;
}
}
import { Injectable } from '@angular/core';
import { CanLoad, Route, Router } from '@angular/router';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class {{Name}}LoadGuard implements CanLoad {
constructor(
private router: Router,
// private authService: AuthService
) {}
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
// Check if user has permission to load this module
return true;
}
}
const routes: Routes = [
{
path: 'admin',
component: AdminComponent,
canActivate: [AuthGuard],
canActivateChild: [AuthChildGuard],
children: [
{
path: 'users',
component: UsersComponent,
canDeactivate: [UnsavedChangesGuard],
},
],
},
{
path: 'lazy-module',
loadChildren: () => import('./lazy/lazy.module').then((m) => m.LazyModule),
canLoad: [AuthLoadGuard],
},
];
providedIn: 'root' for guards