aws-amplify / aws-amplify/docs
Update Docs how to use Custom Claims / ID Token with GraphQL API and Data Store
- Dominant language
- MDX
- Stars
- 506
- Forks
- 1.1k
- Avg merge
- 3h 14m
- Merged PRs (30d)
- 1
Description
### Is this related to a new or existing framework?
_No response_
### Is this related to a new or existing API?
GraphQL API
### Is this related to another service?
_No response_
### Describe the feature you'd like to request
With the migration from v5 > v6 I was struggling how to pass the ID token with all my custom claims (I generate using a Pre Token Generation Lambda Trigger). Since I was doing this since v5, I needed to look this up for v6 in the docs but did not find it.
The solution is close but not clear! There is a general section how to [Set custom request headers for GraphQL APIs](https://docs.amplify.aws/react-native/build-a-backend/graphqlapi/connect-to-api/#set-custom-request-headers-for-graphql-apis)
```ts
import { Amplify } from 'aws-amplify';
import config from './amplifyconfiguration.json';
Amplify.configure(config, {
API: {
headers: async () => ({
'My-Custom-Header': 'my value'
})
}
});
```
But this is not enough!
### Describe the solution you'd like
There should be a more precise explanation how to pass the ID token when using a Pre Token Generation Lambda Trigger.
```ts
import { Amplify } from 'aws-amplify';
import { fetchAuthSession } from 'aws-amplify/auth';
import config from './amplifyconfiguration.json';
Amplify.configure(config, {
API: {
GraphQL: {
headers: async () => ({
Authorization: (
await fetchAuthSession()
).tokens?.idToken?.toString() as string,
}),
},
},
});
```
### Describe alternatives you've considered
My approach is working fine, just update the docs 😉
### Additional context
_No response_
### Is this something that you'd be interested in working on?
- [ ] 👋 I may be able to implement this feature request
- [ ] ⚠️ This feature might incur a breaking change
Contributor guide
Assessment
This issue has not been assessed yet.