Amplify-js: aws-amplify ^1.2.5-unstable.13 : Unhandled Rejection (TypeError): Cannot read property 'clientMetadata' of undefined

Created on 15 Nov 2019  路  4Comments  路  Source: aws-amplify/amplify-js

im using the unstable version bc i need some changes there in order to work fine with NextJs framework. But, when im trying the basic funcionality:

await Auth.signIn({ username, password, }) .then(data => { console.log('authData=>', data); }) .catch(err => { console.log('errLogin=>', err); });

I got the next error message:
Unhandled Rejection (TypeError): Cannot read property 'clientMetadata' of undefined
AuthClass.push../node_modules/@aws-amplify/auth/lib-esm/Auth.js.AuthClass.signIn.

may you please give me any advice to fix this?

pending-close-response-required question

Most helpful comment

All 4 comments

@DsEsteban what does your next.config.js file look like? See working example here:
https://github.com/aws-amplify/amplify-js/issues/3854#issuecomment-554702182

@DsEsteban After using the next.config.js that @mlabieniec cites above, I have authentication working on a very basic next.js app which looks like this:

import React from 'react';
import {ReactDOM } from 'react-dom';
import './App.css';
import { Authenticator, withAuthenticator } from 'aws-amplify-react';
import Amplify, {Auth} from 'aws-amplify';
// Get the aws resources configuration parameters
import awsconfig from './aws-exports'; // if you are using Amplify CLI

Auth.configure(awsconfig);

const signIn = async() => {
    await Auth.signIn({ username:'testuser', password:'testpw', }) .then(data => { console.log('authData=>', data); }) .catch(err => { console.log('errLogin=>', err); });
}

function App() {
  return (
    <div className="App">
      <header className="App-header">
        <button onClick={signIn}>Sign In</button>
      </header>
    </div>
  );
}

export default App;

As you can see I'm more or less using the .signIn code sample you've provided. Have you tried using the config @mlabieniec suggests? I don't think that's necessarily the root of your issue, but it's worth a shot. Also, is this happening with a standard 'npm run dev' or in some other particular case?

Closing this issue due to inactivity.

Was this page helpful?
0 / 5 - 0 ratings