aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.41k stars 2.11k forks source link

AuthError - Error: Amplify has not been configured correctly. The configuration object is missing required auth properties #11794

Closed kpickreign22 closed 11 months ago

kpickreign22 commented 1 year ago

Before opening, please confirm:

JavaScript Framework

Not applicable

Amplify APIs

Authentication

Amplify Categories

auth

Environment information

``` # Put output below this line System: OS: macOS 13.0 CPU: (10) arm64 Apple M1 Max Memory: 255.94 MB / 32.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 18.16.1 - /usr/local/bin/node npm: 9.5.1 - /usr/local/bin/npm Browsers: Chrome: 115.0.5790.170 Safari: 16.1 npmPackages: @aws-amplify/analytics: ^6.5.1 => 6.5.1 @aws-amplify/api: ^5.4.1 => 5.4.1 @aws-amplify/api/internals: undefined () @aws-amplify/auth: ^5.6.1 => 5.6.1 @aws-amplify/auth/internals: undefined () @aws-amplify/core: ^5.8.1 => 5.8.1 (5.0.15) @aws-amplify/core/internals/aws-client-utils: undefined () @aws-amplify/core/internals/aws-client-utils/composers: undefined () @aws-amplify/core/internals/aws-clients/pinpoint: undefined () @aws-amplify/interactions: ^5.2.7 => 5.2.7 @aws-amplify/storage: ^5.9.1 => 5.9.1 @aws-amplify/storage/internals: undefined () @aws-amplify/xr: ^4.0.15 => 4.0.15 @aws-sdk/client-lex-runtime-service: latest => 3.388.0 (3.186.3) @aws-sdk/client-lex-runtime-v2: latest => 3.388.0 (3.186.3) @aws-sdk/client-location: latest => 3.388.0 (3.186.3) @aws-sdk/client-sso: latest => 3.387.0 (3.186.0) @aws-sdk/client-sts: latest => 3.388.0 (3.186.3) @electron-forge/cli: ^6.2.1 => 6.3.0 @electron-forge/maker-deb: ^6.2.1 => 6.3.0 @electron-forge/maker-rpm: ^6.2.1 => 6.3.0 @electron-forge/maker-squirrel: ^6.2.1 => 6.3.0 @electron-forge/maker-zip: ^6.2.1 => 6.3.0 @electron-forge/plugin-auto-unpack-natives: ^6.2.1 => 6.3.0 aws-amplify: ^5.3.6 => 5.3.7 copy-webpack-plugin: ^11.0.0 => 11.0.0 electron: ^25.5.0 => 25.5.0 electron-squirrel-startup: ^1.0.0 => 1.0.0 fs-extra: ^11.1.1 => 11.1.1 (10.1.0, 8.1.0, 9.1.0, 7.0.1, 4.0.3) path-browserify: ^1.0.1 => 1.0.1 webpack: ^5.88.2 => 5.88.2 webpack-cli: ^5.1.4 => 5.1.4 webpack-dev-server: ^4.15.1 => 4.15.1 npmGlobalPackages: corepack: 0.17.0 grunt-cli: 1.1.0 n: 9.1.0 npm: 9.5.1 ```

Describe the bug

I am making an electron desktop app with Amplify. When I try to sign up a user I get the below error wich seems common for amplify:

VM9640 ConsoleLogger.js:125 [ERROR] 00:14.280 AuthError - Error: Amplify has not been configured correctly. The configuration object is missing required auth properties.

    1. Did you run `amplify push` after adding auth via `amplify add auth`?
        See https://aws-amplify.github.io/docs/js/authentication#amplify-project-setup for more information

    2. This could also be caused by multiple conflicting versions of amplify packages, see (https://docs.amplify.aws/lib/troubleshooting/upgrading/q/platform/js) for help upgrading Amplify packages.

Expected behavior

I am expecting to be able to sign up a user using Amplify.

Reproduction steps

create electron forge app install amplify configure amplify in main.js set up signup in proload.js call sign up in signup.js

Code Snippet

main.js:

const path = require('path');
const os = require('os');
const fs = require('fs');
const {app, BrowserWindow, Menu, ipcMain, shell} = require('electron');
const isMac = process.platform === 'darwin';
const isDev = process.env.NODE_ENV !== 'production';

const { Amplify, Auth } = require('aws-amplify');
const awsmobile = require('./aws-exports.js');

console.log(awsmobile)

Amplify.configure(awsmobile);
Auth.configure(awsmobile);

let win;

function createWindow() { ...

signup.js:

async function signUp() {
  const username = document.getElementById('username').value;
  const password = document.getElementById('password').value;
  const email = document.getElementById('email').value;
  const phone_number = document.getElementById('phone_number').value;
  const name = document.getElementById('name').value;

  try {
    const user = await Amplify.signUp({
      username,
      password,
      attributes: {
        email,
        phone_number,
        name,
      },
    });
    alert('Sign up successful');
    console.log('User:', user);
  } catch (error) {
    console.log('Error signing up:', error);
    alert('Sign up failed. Please check your inputs and try again.');
  }
}

document.addEventListener('DOMContentLoaded', function() {
  const signupButton = document.getElementById('signup-button');
  signupButton.addEventListener('click', signUp);
});

document.addEventListener('DOMContentLoaded', function () {
  const backButton = document.getElementById('back-button');

  backButton.addEventListener('click', function () {
    history.back(); // Go back to the previous page
  });
});

preload.js:

contextBridge.exposeInMainWorld('Amplify', { 
  Auth: Amplify.Auth,
  awsmobile: awsmobile,
  signUp: async (username, password, email, phone_number, name) => {
    try {
      const { user } = await Amplify.Auth.signUp({
        username,
        password,
        attributes: {
          email,
          phone_number,
          name
        },
      });
      return user;
    } catch (error) {
      throw error;
    }
  }

}); 

Log output

``` // Put your logs below this line VM4904 ConsoleLogger.js:125 [ERROR] 23:06.281 AuthError - Error: Amplify has not been configured correctly. The configuration object is missing required auth properties. This error is typically caused by one of the following scenarios: 1. Did you run `amplify push` after adding auth via `amplify add auth`? See https://aws-amplify.github.io/docs/js/authentication#amplify-project-setup for more information 2. This could also be caused by multiple conflicting versions of amplify packages, see (https://docs.amplify.aws/lib/troubleshooting/upgrading/q/platform/js) for help upgrading Amplify packages. ```

aws-exports.js

const awsmobile = {
    "aws_project_region": "XXXXXXXXXXXXXXXXXXXXXX",
    "aws_cognito_identity_pool_id":"XXXXXXXXXXXXXXXXXXXXXX",
    "aws_cognito_region": "XXXXXXXXXXXXXXXXXXXXXX",
    "aws_user_pools_id": "XXXXXXXXXXXXXXXXXXXXXX",
    "aws_user_pools_web_client_id": "XXXXXXXXXXXXXXXXXXXXXX",
    "oauth": {},
    "aws_cognito_username_attributes": [],
    "aws_cognito_social_providers": [],
    "aws_cognito_signup_attributes": [
        "EMAIL",
        "PHONE_NUMBER",
        "NAME"
    ],
    "aws_cognito_mfa_configuration": "OFF",
    "aws_cognito_mfa_types": [
        "SMS"
    ],
    "aws_cognito_password_protection_settings": {
        "passwordPolicyMinLength": 6,
        "passwordPolicyCharacters": [
            "REQUIRES_LOWERCASE",
            "REQUIRES_NUMBERS",
            "REQUIRES_SYMBOLS",
            "REQUIRES_UPPERCASE"
        ]
    },
    "aws_cognito_verification_mechanisms": [
        "EMAIL"
    ]
};

module.exports = awsmobile;

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

nadetastic commented 1 year ago

Hi @kpickreign22, thanks for opening this issue. I'm taking a look into this and one thing I wanted to point out is that you shouldn't need to call Auth.configure(awsmobile) since you already have Amplify.configure(awsmobile) I haven't tried to reproduce this yet, but could you remove the second call Auth.configure() just to be sure that there aren't any conflicts happening?

Additionally, be sure to confirm that Amplify.configure() is being called at the entry point of your app.

kpickreign22 commented 1 year ago

Originally I only used Amplify.configure(awsmobile) but multiple people used both Auth and Amplify and it worked. However, neither works. Amplify.configure(awsmobile) is being called in main.js - electron app entry point.

Kongbi-Zion commented 1 year ago

Hi there,

currently facing the same issue in my Nuxt.js application when ever I turn server side rendering (SSR) on but works fine in SPA mode

cwomack commented 12 months ago

@kpickreign22, can you please share you full package.json?

and @Kongbi-Zion, are you getting the same error reported here? If so, would you mind also sharing what you have for dependencies in your package.json and possibly some of the frontend code making Auth calls?

nadetastic commented 11 months ago

Hi @kpickreign22 following up here - i haven't been able to reproduce this issue in an electron app. Can you confirm the versions you were facing this issue on?

These are the versions that work fine for me

{
  "devDependencies": {
    "electron": "^26.1.0"
  },
  "dependencies": {
    "aws-amplify": "^5.3.10"
  }
}

I've also setup a mini electron app that utilizes amplify auth here - https://github.com/nadetastic/electron-amplified

nadetastic commented 11 months ago

Hi @kpickreign22 , im going to close out this issue as there hasn't been any response in a while. If you still have questions please let me know and we can continue discussing. Thanks!