Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read roles in the front end #703

Open
reefdog opened this issue Apr 23, 2024 · 0 comments
Open

Read roles in the front end #703

reefdog opened this issue Apr 23, 2024 · 0 comments
Assignees

Comments

@reefdog
Copy link
Contributor

reefdog commented Apr 23, 2024

We now have (and use) roles for authorization of certain API features. Consequently, the front end needs to gate certain functionality based on those roles. What's the best way to read them? What's a good convention for doing role-based checks? Do we have a bunch of feature checks like canSeeAllProposals() that route back to a centralize role check? Or do we just do role checks inline like isAdmin()?

I'll note that I can read our roles with the following code, but only if I disable a bunch of ESLint warnings (as shown). Hoping someone can help me sort this out:

import { useOidcAccessToken } from '@axa-fr/react-oidc';

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { accessTokenPayload: { realm_access: { roles } } } = useOidcAccessToken();
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
const isAdmin = roles.includes('pdc-admin');

@slifty I'd appreciate your eyes on the ESLint / TypeScript warnings specifically (i.e. the right way to read the roles), but also your architectural thoughts on how to apply the roles to front-end feature gatekeeping.

@reefdog reefdog assigned reefdog and hminsky2002 and unassigned reefdog and hminsky2002 Apr 23, 2024
@reefdog reefdog assigned hminsky2002 and unassigned reefdog May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

2 participants