project_next_14_ai_prompt_sharing
project_next_14_ai_prompt_sharing copied to clipboard
Access denied.
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.
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
change callbacks to callback
Changing callbacks to callback will not work. Check this solution: #52
dont try to change cause async signin and session not be running
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 }
Changing
callbackstocallbackwill not work. Check this solution: #52
thanks
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