project_next_14_ai_prompt_sharing icon indicating copy to clipboard operation
project_next_14_ai_prompt_sharing copied to clipboard

Access Denied Error

Open aqilmarwan opened this issue 1 year ago • 12 comments

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 MONGODB_URI
  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

aqilmarwan avatar Jun 10 '23 22:06 aqilmarwan

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

pratikgrv avatar Jun 11 '23 16:06 pratikgrv

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.

aqilmarwan avatar Jun 11 '23 17:06 aqilmarwan

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

levelingup avatar Jun 11 '23 20:06 levelingup

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

aqilmarwan avatar Jun 12 '23 05:06 aqilmarwan

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?

levelingup avatar Jun 13 '23 18:06 levelingup

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

aqilmarwan avatar Jun 16 '23 06:06 aqilmarwan

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

    added    .replaceAll(" ", "").toLowerCase(),
    
    

somashekhar161 avatar Jun 17 '23 11:06 somashekhar161

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`

StefDev117 avatar Jun 17 '23 12:06 StefDev117

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)".

StefDev117 avatar Jun 17 '23 12:06 StefDev117

@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.

vorteg avatar Jun 17 '23 15:06 vorteg

@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

levelingup avatar Jun 17 '23 16:06 levelingup

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

hungnhu95 avatar Jul 18 '23 15:07 hungnhu95