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
175 stars 60 forks source link

Authenticator throws error when adding addition external provider to auth #1635

Closed strickon closed 4 months ago

strickon commented 4 months ago

Environment information

System:
  OS: macOS 14.5
  CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  Memory: 3.12 GB / 64.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 20.12.0 - /usr/local/bin/node
  Yarn: undefined - undefined
  npm: 10.5.0 - /usr/local/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/backend: 0.15.1
  @aws-amplify/backend-cli: 0.15.0
  aws-amplify: 6.3.0
  aws-cdk: 2.140.0
  aws-cdk-lib: 2.140.0
  typescript: 5.4.5
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 have setup a test app in nextjs using email in define auth. I am logging in using withauthenticator and everything works fine. Once I add my external SAML provider in my defineAuth, the authenticator throws an error. I understand that the authenticator won't use SAML yet and I have a workaround to use a button in the footer. However, this shouldn't cause the email login to longer work. It seems that there should be some way to default to email. The examples of using Facebook, Google and Apple definitely allow for multiple providers.

app-index.js:35 Missing onError handler for invocation 'authenticator.setup.getConfig:invocation[0]', error was 'TypeError: Cannot read properties of undefined (reading 'toString')'. Stacktrace was 'TypeError: Cannot read properties of undefined (reading 'toString')

My define auth is similar to this but using saml instead. If I remove the authenticator and only use my saml login button with sigininwithredirect, my saml redirects fine. So it appears is something in how the react authenticator component is handling the list of auth providers.

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

export const auth = defineAuth({ loginWith: { email: true, externalProviders: { oidc: [ { name: 'MicrosoftEntraID', clientId: secret('MICROSOFT_ENTRA_ID_CLIENT_ID'), clientSecret: secret('MICROSOFT_ENTRA_ID_CLIENT_SECRET'), issuerUrl: '', }, ], logoutUrls: ['http://localhost:3000/', 'https://mywebsite.com'], callbackUrls: [ 'http://localhost:3000/profile', 'https://mywebsite.com/profile', ], }, }, });

ykethan commented 4 months ago

Hey @strickon, thank you for reaching out. The issue appears to be similar to https://github.com/aws-amplify/amplify-js/issues/13466. A fix was released on aws-amplify@6.3.6 could you upgrade to latest version of the package and retry this.

ykethan commented 4 months ago

Closing this issue as duplicate, if you do experience the issue after the upgrade do add a comment on https://github.com/aws-amplify/amplify-js/issues/13466.

strickon commented 4 months ago

the update fixed the issue