My code:
@Injectable()
export class UserRouteAccessService implements CanActivate {
authorized = [
'AGREEMENTS_VIEW',
'PROSPECTS_VIEW',
'AGREEMENTS_INSERT_UPDATE',
'PRODUCTS_INSERT_UPDATE',
'PROSPECTS_INSERT_UPDATE',
'DOCUMENTS_VIEW',
'DOCUMENTS_INSERT_UPDATE',
];
constructor(private router: Router, private securityService: CralSecurityService) {
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
//boolean var
this.securityService.securityActions().subscribe(
data => {
//control if auth. is correct
//if yes set true
//if not set false
},
error => {
//return an error
}
)
//return boolean
}
}
The comments are what id like to do but i cant really know what should i write since this is my first time working with angular 4.
Basically I want to set True if some of the params from authorized are sent and false if there are no params in the service.
I hope this is clear, if you need more infos tell me :)
Service:
securityActions(): Observable<any> {
return this.http.post<Observable<any>>(
`${this.ENDPOINT}/security-actions`,
null,
);
}