Skip to content

Commit 62d03f0

Browse files
committed
feat: method to get list of groups
1 parent f50dc89 commit 62d03f0

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/http/auth.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,16 @@ export abstract class CognitoAuthorizer {
8484
}
8585
}
8686

87+
public getGroups(): string[] {
88+
if (!this.isAuthenticated() || !this.claims!.hasOwnProperty('cognito:groups')) {
89+
return [];
90+
}
91+
return this.claims!['cognito:groups'] as unknown as string[];
92+
}
93+
8794
public hasGroup(group: string): boolean {
8895
// 'cognito:groups': [ 'admin' ],
89-
return this.isAuthenticated()
90-
&& this.claims!.hasOwnProperty('cognito:groups')
91-
&& (this.claims!['cognito:groups'] as unknown as string[]).includes(group);
96+
return this.getGroups().includes(group);
9297
}
9398

9499
public assertGroup(group: string): void {

0 commit comments

Comments
 (0)