adrianhajdin / project_next_14_ai_prompt_sharing

Next.js recently became the official React framework as outlined in React docs. In this course, you'll learn the most important Next.js concepts and how they fit into the React ecosystem. Finally, you'll put your skills to the test by building a modern full-stack Next 14 application.
https://www.jsmastery.pro/ultimate-next-course
2.9k stars 426 forks source link

Access Denied Error #30

Open aqilmarwan opened 1 year ago

aqilmarwan commented 1 year ago

Tried every possible ways but still didn't get through.

  1. Make sure the password match in .env and MONGO DB. I noticed sometimes the password does not update if you changed it.
  2. Make sure the < > are removed in the env file for the _MONGODBURI
  3. Make sure you add your email as an authorize tester in the Google Cloud project
  4. Make sure there are no trailing spaces in the IDs
  5. Also, make sure the user role is set to read and write. You can find this when you select the Atlas project, Security > Database Access > Edit > Built-in Role, and select it from the dropdown

Screenshot 2023-06-11 at 6 25 58 AM

pratikgrv commented 1 year ago

username: { type: String, required: [true, 'Username is required!'], // match: [/^(?=.{8,20}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$/, "Username invalid, it should contain 8-20 alphanumeric letters and be unique!"] }, remove this match: and try again

aqilmarwan commented 1 year ago

username: { type: String, required: [true, 'Username is required!'], // match: [/^(?=.{8,20}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$/, "Username invalid, it should contain 8-20 alphanumeric letters and be unique!"] }, remove this match: and try again

Commented/deleted the match lines out and tried using match: [/^(?=.{8,20}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$/, "Username invalid, it should contain 8-20 alphanumeric letters and be unique!"], still didn't get through the authentication.

levelingup commented 1 year ago

do you have a repo up so we can see what you did wrong?

aqilmarwan commented 1 year ago

do you have a repo up so we can see what you did wrong?

I didn't change anything except for (env & match lines) to make it runs on my local machine. https://github.com/aqilmarwan/promptopia

levelingup commented 1 year ago

I was having this issue before too. This is after you signed in with google? How did you get to this access denied? Do you have your google URL and callbacks to localhost?

aqilmarwan commented 1 year ago

I was having this issue before too. This is after you signed in with google? How did you get to this access denied? Do you have your google URL and callbacks to localhost?

yes i have that called in google auth

somashekhar161 commented 1 year ago

if (!userExists) { await User.create({ email: profile.email, username: profile.name.replaceAll(" ", "").toLowerCase(), image: profile.picture, }); }

    added    .replaceAll(" ", "").toLowerCase(),
StefDev117 commented 1 year ago

I checked what you recommended, MongoDb looks to be connected. But I get always have the access denied, I got this in the terminal when I click on signIn:

`- wait compiling /api/auth/[...nextauth]/route (client and server)...

StefDev117 commented 1 year ago

I checked what you recommended, MongoDb looks to be connected. But I get always have the access denied, I got this in the terminal when I click on signIn:

`- wait compiling /api/auth/[...nextauth]/route (client and server)...

  • event compiled client and server successfully in 774 ms (776 modules) MongoDB connected Error checking if user exists: _models_user__WEBPACK_IMPORTED_MODULE_2__.default.findOne is not a function`

I finally find it and get an error in models >user.js, stupid error. I write : "const User = models.User || ("User", UserSchema)" instead of "const User = models.User || model("User", UserSchema)".

vorteg commented 1 year ago

@aqilmarwan I encountered an 'Access Denied' error with the following message: 'Username invalid, it should contain 8-20 alphanumeric letters and be unique!' I tried using another Google account, and it worked correctly. Then, I realized that the denied Google account had my full name as the username, which exceeded the character limit allowed by the MongoDB model. I changed my name in the Google account to confirm, and it worked. However, this is not a production-ready solution. To address this issue, one can modify the model to allow a broader range of username types by customizing the UserSchema in the 'const User' object. Best regards.

levelingup commented 1 year ago

@aqilmarwan I encountered an 'Access Denied' error with the following message: 'Username invalid, it should contain 8-20 alphanumeric letters and be unique!' I tried using another Google account, and it worked correctly. Then, I realized that the denied Google account had my full name as the username, which exceeded the character limit allowed by the MongoDB model. I changed my name in the Google account to confirm, and it worked. However, this is not a production-ready solution. To address this issue, one can modify the model to allow a broader range of username types by customizing the UserSchema in the 'const User' object. Best regards.

You can uoda6e the regex for the username

hungnhu95 commented 1 year ago

change MONGODB_URI back to older version and comment to disable "match" line in user.js model and code will run. Goodluck image