Closed chrchng closed 9 months ago
Hii @chrchng thank you for opening this issue.
Can you verify what version of aws-amplify
your project is installed with? We recently released V6 of the library and the import have changed. Essentially, if your project is using V6, then the error you see is expected as we no longer export Auth
but instead export the specific methods.
For example:
Also take a look at the migration guide shared by @yaraboec above.
Thanks.
Hi @nadetastic ,
I'm having the same issues. I studied the documentation, but I still feel lost. My main issue is the basic configuration that we do via the Auth.configure()
method:
import { Auth } from '@aws-amplify/auth';
Auth.configure({
region: Config.cognito.REGION,
userPoolId: Config.cognito.POOL_ID,
userPoolWebClientId: Config.cognito.CLIENT_APP_ID,
authenticationFlowType: 'USER_PASSWORD_AUTH',
cookieStorage: {
domain: DOMAIN,
path: '/',
expires: 365,
sameSite: 'lax',
}
});
I haven't found a way yet to do this with V6.
Can you give me a hint how to do this configuration for V6?
Hi @mzagel , in V6 you configure auth using Amplify.configure()
https://docs.amplify.aws/nextjs/tools/libraries/configure-categories/#scoped-configuration
Hi @louisthomaspro ,
thanks for the hint. The scoped configuration looks somewhat like what I need. However when I try to configure it that way the properties don't exist. According to the types the Auth
type only contains a property Cognito
, nothing else.
What am I missing?
Do I maybe need another npm package?
Same for me...
@mzagel @louisthomaspro the scoped config is the proper way to do this but the documentation is not inline with how V6 works. Im currently working to udpate however here is how you would set it:
Amplify.configure({
Auth: {
Cognito: {
userPoolClientId: '',
userPoolId: '',
identityPoolId: '',
},
},
});
The Cognito
object is where you would pass your backend resources.
As for the authentication flow, you would set that when you call signIn()
as shown here instead of passing it into Amplify.configure()
signIn({
username,
password,
options: {
authFlowType: 'USER_PASSWORD_AUTH'
}
})
I think the key here is that the imports and calls are different now.
import { signUp } from 'aws-amplify/auth';
async function handleSignUp({ username, password, email, phone_number }) {
try {
const { isSignUpComplete, userId, nextStep } = await signUp({
username,
password,
options: {
userAttributes: {
email,
phone_number // E.164 number convention
},
}
});
console.log(userId);
} catch (error) {
console.log('error signing up:', error);
}
}
@nadetastic Thanks for the hints. I was now able to get a version running. However I'm still struggling with two configurations:
cookieStorage: {
domain: DOMAIN,
path: '/',
expires: 365,
sameSite: 'lax',
}
region
. This property however does not exist in the Cognito
settings. Where did this setting go?@mzagel you can configure your cookie storage as shown in the documentation here and as shown in this code sample:
import { Amplify, type ResourcesConfig } from 'aws-amplify';
import { defaultStorage } from 'aws-amplify/utils';
import { cognitoUserPoolsTokenProvider } from 'aws-amplify/auth/cognito';
const authConfig: ResourcesConfig['Auth'] = {
Cognito: {
userPoolId: 'your_user_pool_id',
userPoolClientId: 'your_user_pool_client_id'
}
};
Amplify.configure({
Auth: authConfig
});
cognitoUserPoolsTokenProvider.setKeyValueStorage(defaultStorage);
As for the region, you no longer need to set that value.
Hi @mzagel following up - let me know if you still need assistance here, if not I'll go ahead and close out this issue. Thanks!
Hi @nadetastic , sorry for the late reply. I was on holiday last week.
I just implemented the cookie storage and it seems to work perfectly.
Thanks a lot for your help!
@mzagel you're welcome! Glad to hear you are unblocked.
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Authentication
Amplify Categories
auth
Environment information
Describe the bug
I am currently following this tutorial: https://youtu.be/-QcEMHqndzw?list=PLGyRwGktEFqebocpKlgAEoVssEyhXpRFP&t=971 and receive the following error when viewing the app web page:
The associated code is found here: https://github.com/mavi888/amplify-location
My current App.js code is as:
Expected behavior
The web page should display a map similar to
Reproduction steps
Code Snippet
// Put your logs below this line