Skip to content

Update Docs how to use Custom Claims / ID Token with GraphQL API and Data Store #6513

Open
@jgo80

Description

@jgo80

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

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.

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

Metadata

Metadata

Assignees

Labels

API GraphQLamplify/jsIssues tied to JStransferredThis issue was transferred from another Amplify project

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions