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.58k stars 396 forks source link

[FIX 100%] Access Denied Issue & empty collections in DataBase #92

Open getFrontend opened 4 months ago

getFrontend commented 4 months ago

Guys, if you are facing "Access Denied Issue" problem, now I am going to write you 100% solution to the problem 99% of the time. I came to the solution of this problem by re-reading all previous posts and trying all the tips, which in the end did not help, until I found this solution.

1) So, the first thing to do is to make sure that the connection to the database is actually being made and the following message appears in the console "MongoDB successfully conected".

Don't listen to advice like "rename callbacks to callback". This is absolutely wrong advice! According to the documentation it should be "callbacks".

It also doesn't matter whether you have commented outdated rules or not

// useNewUrlParser: true,
// useUnifiedTopology: true,

2) And now the most important thing! In user.js Adrian made essentially unnecessary login validation "Username invalid, it should contain 8-20 alphanumeric letters and be unique!", because we just substitute a ready-made login from Google instead of entering it manually. Because of this, the error occurred, because the login could contain characters, for example for Ukrainian - Cyrillic, or be shorter than 8 characters, or longer than 20.

Just remove this unnecessary validation, and everything will work at once! Good luck!

P.S. Suppose you want to leave the validation, and add for example Cyrillic characters, then you will need this template:

/^(?=.{3,20}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._\u0400-\u04FF]+(?<![_.])$/

Pheeleex commented 4 months ago

It still didn't work for me

getFrontend commented 4 months ago

It still didn't work for me

Check first if you have a connection to the database and if a message appears in the console?

Onunkwor commented 4 months ago

@Pheeleex what worked for me was logging the information I received from google

Screenshot 2024-02-19 211654

adrian used profile.name for the user name but the data received from the profile had no name for me it was given_name so I used that instead and it worked for me also make sure the schema matched the User.create e.g in the schema I used userName but I used username in the username in the User.create

Screenshot 2024-02-19 211718
Pheeleex commented 4 months ago

@getFrontend yeah, it shows mongoDb is connected on my terminal and the user appears in my mongoDB collection, i just keep getting a not permitted to sign in error each time i try.

Pheeleex commented 4 months ago

@Onunkwor okay, I'll try that.