Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Acces Denied Issues #76

Open
tynoschuck opened this issue Dec 3, 2023 · 5 comments
Open

Acces Denied Issues #76

tynoschuck opened this issue Dec 3, 2023 · 5 comments

Comments

@tynoschuck
Copy link

tynoschuck commented Dec 3, 2023

Hello there!
Nothing new here, same issue as already discussed, I tried everything already mentioned in the other posts, and I came to a dead end.
Here's my user.js
Screenshot 2023-12-03 at 14 10 49

route.js
Screenshot 2023-12-03 at 14 11 17

and database
Screenshot 2023-12-03 at 14 14 54

Hope that someone would be able to help. Thank in advance!

@aabu960
Copy link

aabu960 commented Dec 17, 2023

  1. copy the code below and past in your [...nextauth] router.js

import NextAuth from 'next-auth';
import GoogleProvider from 'next-auth/providers/google';

import User from '@models/user';
import { connectToDB } from '@utils/database';

const handler = NextAuth({
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
})
],
callback: {
async session({ session }) {

  const sessionUser = await User.findOne({ email: session.user.email });
  session.user.id = sessionUser._id.toString();

  return session
},
async signIn({ user, account, profile, email, credentials }) {
  try {
    await connectToDB();
    const userExists = await User.findOne({ email: profile?.email });
    // if not, create a new document and save user in MongoDB
    if (userExists === null) {
      await User.create({
        email: profile?.email,
        username: profile?.name.replace(/\s+/g, '').toLowerCase(),
        image: user.image
      })
    }

    return true
  } catch (error) {
    console.log(error);
    return false
  }
  
} 

}
})

export { handler as GET, handler as POST }

  1. in your next.config.js copy the code and paste below
    // next.config.js
    const nextConfig = {
    images: {
    domains: ['lh3.googleusercontent.com'],
    },
    };

module.exports = nextConfig;

@tynoschuck
Copy link
Author

Thanks for the reply! Unfortunately changing callbacks to callback does not solve the problem, I do not receive errors but it does nopt connect to the database as it should.

@Pannu786
Copy link

Thanks for the reply! Unfortunately changing callbacks to callback does not solve the problem, I do not receive errors but it does nopt connect to the database as it should.

same here stuck at this issue for ages now. I have tried everything but no luck so far.

@shuuwolf
Copy link

shuuwolf commented Dec 26, 2023

I fixed it following others topic....
Changing the regex at user.js (/models), to allow less than 8 characters...
and removing the brackets on MONGODB_URI when changing the password at .env file

@nimroddanielmaayan
Copy link

nimroddanielmaayan commented Dec 28, 2023

This issue is also caused by any Google account that has non-latin letters in the user name! The solution is to completely disable limitations on the user name at at user.js (/models). This will allow duplicate user names, but I have no problem with that.

I've spent 2 hours on this before solving it... Thanks a lot for the help, shuuwolf

I fixed it following others topic.... Changing the regex at user.js (/models), to allow less than 8 characters... and removing the brackets on MONGODB_URI when changing the password at .env file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants