graphql-hive / graphql-hive/envelop
Provide an `extendContextProvider` option for `useAuth0`
- Dominant language
- No language data
- Stars
- 827
- Forks
- 132
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
After validating the token from the authorization header, the Auth0 plugin provides an `_auth0` object containing the raw payload. It would often be more useful to provide a custom representation of that data that's more semantically useful to the application, and to also avoid polluting the context with this cryptic object.
**Describe the solution you'd like**
Add an `extendContextProvider` option that allows specifying a custom mapping function that controls the changes made to the context:
```typescript
useAuth0({
extendContextProvider: (context, userPayload, rawHeaderValue) => ({
user: !userPayload ? undefined : {
id: userPayload.sub,
fullName: userPayload['name'] || undefined,
isAdmin: userPayload['isAdmin'] === true,
permissions: userPayload['permissions'] ?? [],
},
}),
// ...
})
```
**Describe alternatives you've considered**
We currently just leave the `_auth0` object in the context and add our own plugin to do the transformation, but the existence of the other field is confusing.
The other obvious solution would be to write our own helper function used in place of `useAuth0`.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.