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?
try it:
Amplify.configure()
https://aws-amplify.github.io/docs/js/authentication
@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.
Most helpful comment
try it:
Amplify.configure()https://aws-amplify.github.io/docs/js/authentication