ErikCH / GithubLoginAWSAmplifyGen2

Shows how to Login with Github
4 stars 1 forks source link

amplifyconfiguration.json doesn't exist #1

Open ataylorme opened 1 week ago

ataylorme commented 1 week ago

Howdy 👋, first of all, thank you for making the video and providing this repo with the code sample! When using npx ampx sandbox I am not getting a amplifyconfiguration.json file. There is amplify_outputs.json but that doesn't have the REST API information.

Reading through the Amplify gen2 docs I think backend.addOutput is needed to add the REST API info to amplify_outputs.json.

I am hoping you can update Auth.tsx to use amplify_outputs.json instead of amplifyconfiguration.json and even get the REST API URL dynamically

ataylorme commented 1 week ago

I was able to get the values I needed from amplify_outputs.json

Auth.tsx now looks like this:

import amplifyOutputs from '../amplify_outputs.json';

Amplify.configure(
  {
    Auth: {
      Cognito: {
        userPoolId: amplifyOutputs.auth.user_pool_id,
        userPoolClientId: amplifyOutputs.auth.user_pool_client_id,
        identityPoolId: amplifyOutputs.auth.identity_pool_id,

I was also able to get the custom API added to amplify_outputs.json by adding this to backend.ts:

backend.addOutput({
  custom: {
    API: {
      [ghProvider.api.restApiName]: {
        endpoint: ghProvider.apiUrl,
        region: Stack.of(ghProvider.api).region,
        apiName: ghProvider.api.restApiName,
      },
    },
  },
});

I can then be used in Amplify.configure like this:

API: {
      REST: {
        api: {
          endpoint: amplifyOutputs.custom.API['GitHub API Gateway'].endpoint,
        },
      },
    },

I can make a PR if you are interested, let me know