aws-amplify / amplify-backend

Home to all tools related to Amplify's code-first DX (Gen 2) for building fullstack apps on AWS
Apache License 2.0
185 stars 62 forks source link

Amplify Gen2 Authentication Secret not working #1121

Closed ProfessorPinguino closed 8 months ago

ProfessorPinguino commented 8 months ago

Environment information

System:
  OS: macOS 13.6.3
  CPU: (10) arm64 Apple M1 Max
  Memory: 609.23 MB / 64.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 20.11.1 - /opt/homebrew/bin/node
  Yarn: 1.22.18 - /opt/homebrew/bin/yarn
  npm: 10.2.4 - /opt/homebrew/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/backend: 0.13.0-beta.4
  @aws-amplify/backend-cli: 0.12.0-beta.4
  aws-amplify: 6.0.19
  aws-cdk: 2.131.0
  aws-cdk-lib: 2.131.0
  typescript: 5.4.2
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Description

I implemented authentication with NextJS 14 and AWS amplify Gen 2 as specified in the tutorial (https://docs.amplify.aws/gen2/build-a-backend/auth/add-social-provider/). However, the sandbox immediately throws an error. I created the secrets.

import { defineAuth, secret } from '@aws-amplify/backend';

export const auth = defineAuth({
  loginWith: {
    externalProviders: {
      facebook: {
        clientId: secret('FACEBOOK_CLIENT_ID'),
        clientSecret: secret('FACEBOOK_CLIENT_SECRET')
      },
      callbackUrls: [
        'http://localhost:3000/profile',
        'https://mywebsite.com/profile'
      ],
      logoutUrls: ['http://localhost:3000/', 'https://mywebsite.com'],
      domainPrefix: 'subdomain'
    }
  },
});

This is the error thrown by the sandbox

Unable to build Amplify backend. Check your backend definition in the `amplify` folder.
Caused By: Bundling asset amplify-iris-megger-sandbox-83d1948e5c/auth/SecretFetcherResourceProviderLambda/Code/Stage...
✘ [ERROR] Could not resolve "@aws-amplify/backend-secret"

    node_modules/@aws-amplify/backend/lib/engine/backend-secret/lambda/backend_secret_fetcher.js:1:33:
      1 │ import { getSecretClient, } from '@aws-amplify/backend-secret';
        ╵                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  The Yarn Plug'n'Play manifest forbids importing "@aws-amplify/backend-secret" here because it's not listed as a dependency of this package:

    ../../../.pnp.cjs:43:33:
      43 │           "packageDependencies": [\
         ╵                                  ~~

  You can mark the path "@aws-amplify/backend-secret" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
edwardfoyle commented 8 months ago

Hi @ProfessorPinguino, I see Yarn Plug'n'Play mentioned in the error message. We currently do not support Yarn PnP installations. You'll need to use yarn with node_modules instead.

ProfessorPinguino commented 8 months ago

Hi @edwardfoyle , thanks for the quick response. The result is the same, no matter if I use yarn or npm.

ProfessorPinguino commented 8 months ago

I figured it out: If anybody else has that same problem: Yarn creates a .pnp.cjs file when using Yarn Plug'n'Play in general And i don't know if its a bug with yarn or smth wrongly configured with my machine but even when using yarn with node_modules or npm in a specific problem it's not working.

fr60 commented 1 month ago

@ProfessorPinguino Thanks, I found the issue was the .pnp.cjs file as well. It was in my home directory. I deleted the file, ran amplify again and it worked