Hello.
I want to validate if a user belongs to a specific group. I’m writing in Angular 8 the next code:
this.user = await this.okta.getUser();
const result = this.user.groups.find((group) => group === 'ContactAdmin');
if (result) {
return true;
} else {
alert('User is not authorized to perform this operation');
return false;
}
Part of the data in the payload of the token is the next:
“scp”: [
“openid”
],
“sub”: “jhon@trial.com”,
“groups”: [
“Everyone”,
“ContactAdmin”
]
But i am getting the next error in the console:
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'find' of undefined
TypeError: Cannot read property 'find' of undefined (admin.guard.ts:22)
The line 22 is exactly the following::
const result = this.user.groups.find((group) => group === 'ContactAdmin');
Part of the package.json is the following:
“dependencies”: {
“@angular/animations”: “~8.2.13”,
“@angular/cdk”: “~8.2.3”,
“@angular/common”: “~8.2.13”,
“@angular/compiler”: “~8.2.13”,
“@angular/core”: “~8.2.13”,
“@angular/forms”: “~8.2.13”,
“@angular/material”: “^8.2.3”,
“@angular/platform-browser”: “~8.2.13”,
“@angular/platform-browser-dynamic”: “~8.2.13”,
“@angular/router”: “~8.2.13”,
“@okta/okta-angular”: “^1.4.0”,
“@okta/okta-auth-js”: “^2.10.1”,
“@oktadev/schematics”: “^1.0.1”,
“hammerjs”: “^2.0.8”,
“rxjs”: “~6.4.0”,
“tslib”: “^1.10.0”,
“zone.js”: “~0.9.1”
},
“devDependencies”: {
“@angular-devkit/build-angular”: “~0.803.18”,
“@angular/cli”: “~8.3.18”,
“@angular/compiler-cli”: “~8.2.13”,
“@angular/language-service”: “~8.2.13”,
“@types/node”: “~8.9.4”,
“@types/jasmine”: “~3.3.8”,
“@types/jasminewd2”: “~2.0.3”,
“codelyzer”: “^5.0.0”,
“jasmine-core”: “~3.4.0”,
“jasmine-spec-reporter”: “~4.2.1”,
“karma”: “~4.1.0”,
“karma-chrome-launcher”: “~2.2.0”,
“karma-coverage-istanbul-reporter”: “~2.0.1”,
“karma-jasmine”: “~2.0.1”,
“karma-jasmine-html-reporter”: “^1.4.0”,
“protractor”: “~5.4.0”,
“ts-node”: “~7.0.0”,
“tslint”: “~5.15.0”,
“typescript”: “~3.5.3”
}
How can i fix this?
If the problem is because of libraries version. ¿How can i update them?, ¿What version should they be?
Thanks.