Closed casperibo closed 2 years ago
Hey @casperibo, I would enable logs with Amplify.Logger.LOG_LEVEL = 'DEBUG'
and then check the logs in your Next.js app to see there are any warnings or errors coming from DataStore. If there are, please share them here.
Hi @iartemiev thank you for your response, i finally could see an error.
I think DataStore try to use API key when i try to save data.
Normally i would do AUTH_TYPE.AMAZON_COGNITO_USER_POOLS, on API but do i have to declare anything on my DataStore.save command?
I faced some error when try to debug.
[DEBUG] 20:34.280 DataStore - Mutation failed with authMode: API_KEY [DEBUG] 20:34.514 AuthClass - getting current authenticated user [DEBUG] 20:34.514 AuthClass - get current authenticated userpool user [DEBUG] 20:34.514 AuthClass - Failed to get user from user pool [DEBUG] 20:34.515 AuthClass - The user is not authenticated by the error No current user [DEBUG] 20:34.516 DataStore - Attempting sync with authMode: API_KEY
If you can look my code again, I'm getting user from withSSRContext and i can console.log current user successfully.
I console log Auth and Datastore coming from withSSRContext({ req }) and found;
Auth._config.aws_appsync_authenticationType is "API_KEY";
DataStore.amplifyConfig.aws_appsync_authenticationType is "API_KEY";
I try to change them but still getting same "Mutation failed with authMode: API_KEY" error.
// Didn't work
Auth._config.aws_appsync_authenticationType = "COGNITO_USER_POOLS";
DataStore.amplifyConfig.aws_appsync_authenticationType = "COGNITO_USER_POOLS";
Hi @iartemiev can you take a look this situation when you available? I'm still in same situation.
@chrisbonifacio Hi, i saw your message in a aws-amplify issue page(link below), the problem still didn't fixed.
Should i use API in NextJS API routes or is there a way to use DataStore for authenticated requests?
https://github.com/aws-amplify/amplify-js/issues/8454#issuecomment-862827238
This will be fixed in https://github.com/aws-amplify/amplify-js/pull/10088
We released a fix for this issue in aws-amplify@4.3.28
Before opening, please confirm:
JavaScript Framework
Next.js
Amplify APIs
DataStore
Amplify Categories
api
Environment information
Describe the bug
Hi i'm using AWS Amplify with DataStore to create fullstack app and i faced a problem that doesn't go away.
I will describe my problem with a basic example.
Schema:
If i try to save a data to the Post model in NextJS API route it will work but if i add
rule like that and try to save a data, the data will create only locally and not properly.
Here is my API route code example:
Expected behavior
The data should be created on cloud like when i adding data without @auth rule.
Reproduction steps
Try to create data on NextJS API route you probably will facing with the same problem.
Code Snippet
Log output
aws-exports.js
No response
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