project_next_14_ai_prompt_sharing icon indicating copy to clipboard operation
project_next_14_ai_prompt_sharing copied to clipboard

Access denied.

Open Aakash698 opened this issue 2 years ago • 6 comments
trafficstars

MongoServerError: bad auth : authentication failed at Connection.onMessage (C:\Users\ashvi\Desktop\Wizard\node_modules\mongoose\node_modules\mongodb\lib\cmap\connection.js:202:26) at MessageStream. (C:\Users\ashvi\Desktop\Wizard\node_modules\mongoose\node_modules\mongodb\lib\cmap\connection.js:61:60) at MessageStream.emit (node:events:526:28) at processIncomingData (C:\Users\ashvi\Desktop\Wizard\node_modules\mongoose\node_modules\mongodb\lib\cmap\message_stream.js:124:16) at MessageStream._write (C:\Users\ashvi\Desktop\Wizard\node_modules\mongoose\node_modules\mongodb\lib\cmap\message_stream.js:33:9) at writeOrBuffer (node:internal/streams/writable:389:12)
at _write (node:internal/streams/writable:330:10) at MessageStream.Writable.write (node:internal/streams/writable:334:10) at TLSSocket.ondata (node:internal/streams/readable:754:22)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23) at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17) { ok: 0, code: 8000, codeName: 'AtlasError', connectionGeneration: 0, [Symbol(errorLabels)]: Set(2) { 'HandshakeError', 'ResetPool' } } Error checking if user exists: Operation users.findOne() buffering timed out after 10000ms image

Aakash698 avatar Jul 21 '23 17:07 Aakash698

change callbacks to callback

Manmit124 avatar Jul 22 '23 18:07 Manmit124

Changing callbacks to callback will not work. Check this solution: #52

RobItu avatar Jul 25 '23 03:07 RobItu

dont try to change cause async signin and session not be running

raihanachmad8 avatar Jul 31 '23 10:07 raihanachmad8

dont try to change cause async signin and session not be running copy this

the error cause

dont forget check GOOGLE_ID and GOOGLE_ID_SECRET

and google alternative redirect url add http://localhost:3000/api/auth/callback/[provider]

in this case http://localhost:3000/api/auth/callback/google

const userExists = await User.findOne({ email: profile?.email }); userExist = null not boolean

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,
    })
  ],
  callbacks: {
    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 }

raihanachmad8 avatar Jul 31 '23 14:07 raihanachmad8

Changing callbacks to callback will not work. Check this solution: #52

thanks

adekmo avatar Aug 10 '23 08:08 adekmo

hi, if I want to host it what shall I include in the google.cloud.clonsole, and do I need to change anything in my .env file

AbdullahTayeh avatar Aug 11 '23 01:08 AbdullahTayeh