-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
502: BAD_GATEWAY #1021
Comments
I’m getting the same issue on my application when pairing with mongodb. I’ve opened up the IP access, by adding 0.0.0.0/0 but it doesn’t seem to work. Returns 502 after a 10 second timeout. |
Could you please provide some source code? (Ideally a link to a reproduction repository) |
I have same issue with mail auth too. How should I set database url
Error: PS: My mongo db has access from anywhere 0.0.0.0/0 |
NEXTAUTH_URL from vercel dashboardGithub URL'sCodeimport NextAuth from 'next-auth'
import Providers from 'next-auth/providers'
// For more information on each option (and a full list of options) go to
// https://next-auth.js.org/configuration/options
const options = {
// https://next-auth.js.org/configuration/providers
providers: [
Providers.GitHub({
clientId: "13333223131.........",
clientSecret: "13132133........."
}),
Providers.Google({
clientId: "123123...........",
clientSecret: "123123.........."
})
],
// Database optional. MySQL, Maria DB, Postgres and MongoDB are supported.
// https://next-auth.js.org/configuration/database
//
// Notes:
// * You must to install an appropriate node_module for your database
// * The Email provider requires a database (OAuth providers do not)
database: process.env.MONGO_URI,
// The secret should be set to a reasonably long random string.
// It is used to sign cookies and to sign and encrypt JSON Web Tokens, unless
// a seperate secret is defined explicitly for encrypting the JWT.
secret: process.env.SECRET,
session: {
// Use JSON Web Tokens for session instead of database sessions.
// This option can be used with or without a database for users/accounts.
// Note: `jwt` is automatically set to `true` if no database is specified.
jwt: true,
// Seconds - How long until an idle session expires and is no longer valid.
// maxAge: 30 * 24 * 60 * 60, // 30 days
// Seconds - Throttle how frequently to write to database to extend a session.
// Use it to limit write operations. Set to 0 to always update the database.
// Note: This option is ignored if using JSON Web Tokens
// updateAge: 24 * 60 * 60, // 24 hours
},
// JSON Web tokens are only used for sessions if the `jwt: true` session
// option is set - or by default if no database is specified.
// https://next-auth.js.org/configuration/options#jwt
jwt: {
// A secret to use for key generation (you should set this explicitly)
// secret: 'INp8IvdIyeMcoGAgFGoA61DdBglwwSqnXJZkgz8PSnw',
// Set to true to use encryption (default: false)
// encryption: true,
// You can define your own encode/decode functions for signing and encryption
// if you want to override the default behaviour.
// encode: async ({ secret, token, maxAge }) => {},
// decode: async ({ secret, token, maxAge }) => {},
},
// You can define custom pages to override the built-in pages.
// The routes shown here are the default URLs that will be used when a custom
// pages is not specified for that route.
// https://next-auth.js.org/configuration/pages
pages: {
// signIn: '/api/auth/signin', // Displays signin buttons
// signOut: '/api/auth/signout', // Displays form with sign out button
// error: '/api/auth/error', // Error code passed in query string as ?error=
// verifyRequest: '/api/auth/verify-request', // Used for check email page
// newUser: null // If set, new users will be directed here on first sign in
},
// Callbacks are asynchronous functions you can use to control what happens
// when an action is performed.
// https://next-auth.js.org/configuration/callbacks
callbacks: {
// signIn: async (user, account, profile) => { return Promise.resolve(true) },
// redirect: async (url, baseUrl) => { return Promise.resolve(baseUrl) },
// session: async (session, user) => { return Promise.resolve(session) },
// jwt: async (token, user, account, profile, isNewUser) => { return Promise.resolve(token) }
},
// Events are useful for logging
// https://next-auth.js.org/configuration/events
events: { },
// Enable debug messages in the console if you are having problems
debug: false,
}
export default (req, res) => NextAuth(req, res, options) ExplanationThis time, i directly pasted my id and secret into code, It is still not working. But, the strange is that it is working fine on localhost when i provide the |
Client codeimport {signIn} from "next-auth/client";
// uses
<a href="/api/auth/signin"
onClick={(e)=>{
e.preventDefault();
signIn();
}}
>Oauth</a> You can see this link in the footer |
The authorization callback URL should be https://bdevg.com/api/auth/callback/github See: https://next-auth.js.org/getting-started/rest-api#get-apiauthcallbackprovider |
I found the solution like
|
What is this? |
If you have issue on production but localhost. this should work for you. Do not forget to add import _app.js then try. It should work. |
502 bad gateway NO_RESPONSE_FROM_FUNCTION /api/auth/callback/:provider Please see my previous answer. |
I changed Authorization callback URL in my GitHub developer setting to |
Hmm, sorry 😕. "Invalid state returned from oAuth provider" Could you try setting https://next-auth.js.org/configuration/providers#oauth-provider-options |
okey! I'm trying> |
This didn't worked, it takes me http://localhost:3000/api/auth/signin/github after clicking on signin with github or google when i remove, this then it was working as before. |
do you have a link to your repo? |
It's private |
OKey: Repo: https://github.com/ats1999/next-auth-example/tree/main/pages Homepage URL https://next-auth-example-iota.vercel.app
|
I have looked more into this issue. I set up an AWS RDS database to test my application. Everything works correctly in production when doing this. So this means the problem must be to do with how NextAuth is connecting to MongoDB Atlas in production. MongoDB and NextAuth are working correctly in local development. I have the network access set to 0.0.0.0/0. I have tried @bkalafat solution, but it still throws the 502 error. I have also been able to connect to the database using the code found in a Vercel tutorial: https://vercel.com/guides/deploying-a-mongodb-powered-api-with-node-and-vercel So I have to believe the issue is either with NextAuth or MongoDB Atlas is blocking the connection when the site runs on Vercel. If anyone is able to provide a solution to this it would be greatly appreciated. Thanks. |
Can you share your masked mongodb connection string |
Set debug mode to true on your auth options. And be sure typeorm package version is 0.2.28 |
This doesn't logged anything on console. |
In my case, mongodb atlas is correctly working,it is an working application. We can communicate with database, there is no db error. But, still I'm not getting logged in using oauth. |
If i was used normal oauth workflow not nextauth.js, then i would have made it earlier. |
you should set dbname as /nextauth |
nextauth or /nextauth? |
Mine which is working like this for mongodb |
Did you tried DATABASE_URL=mongodb+srv://d**:********@cluster0-yaruk.mongodb.net/anything?retryWrites=true&w=majority Because my DB name is bdevg |
no i am using another db for my application but you should use nextauth for next-auth db name on mongo. I guess its standart for them. Try to add new url path with this /nextauth?.. env file and use that on your next auth options I Have two different path one is for my application another is for my next-auth |
ok |
and you dont have to create db at mongo. Next will generate it automatically |
yeah |
GitHub repo https://github.com/ats1999/next-auth-example if debug: true, then at least it should log error on console. See, my repo for more information. |
i cannot see node modules which I advise you to add. npm install typeorm --save |
npm install typeorm --save which version I have to install, latest or 0.2.28? |
Unpacked Size of Why this large-sized module is required? |
I update the repo as you advised, but no improvement. |
0.2.28 I checked your repo. 0.2.29 is not working you should change it to .28 |
Still, it has the same issue 😂 |
Yes I have tried the many different fixes to no avail. @bkalafat how do you have your MongoDB Atlas configured? What cluster tier/region are you using? I have my Network access set to. Database user role set to Atlas admin. Connection string works locally, but doesn't work when deployed on Vercel. mongodb+srv://pr********:**************@marquee.jiqul.mongodb.net/nextauth?retryWrites=true&w=majority Thanks, Ollie |
Why don't you leave DB configuration on the user? |
@balazsorban44 |
@iaincollins just reverted some changes on the example app, Iain maybe you could give an answer to this? |
I am facing the same problem with google provider and github provider, only works in dev mode, tried many solutions, stuck for 2 days on this error.. |
I'm sure the problem come from the database in [...nextauth].tsx call.
(who the DTABASE_URL is mongodb+srv://[username]>:[password]@strapidbcluster.jdadp.mongodb.net/strapi-db) My configuration for github auth (work perfectly with http://localhost:3000) : My configuration for google auth (work perfectly with http://localhost:3000) : The correct connexion to my backend server and mongo db (handle with strapi) in local dev And in production, always after I tried google or github auth (after clicking on my account) i face the same result: 0 logs, only this message in my vercel function log: I don't know what else to try 😭 My repo just in case : https://github.com/Flosrn/nextjs-headless-cms |
wrong db name |
I think I've finally got it working, try changing 'uri' to 'url' In package.json add: "resolutions": { I've tested without the 'reflect-metadata' package and it also works. Hope this helps everyone. |
Hi there! It looks like this issue hasn't had any activity for a while. It will be closed if no further activity occurs. If you think your issue is still relevant, feel free to comment on it to keep it open. (Read more at #912) Thanks! |
Hi there! It looks like this issue hasn't had any activity for a while. To keep things tidy, I am going to close this issue for now. If you think your issue is still relevant, just leave a comment and I will reopen it. (Read more at #912) Thanks! |
I've the same problem on Azure. |
502: BAD_GATEWAY
While doing GitHub OAuth, i got this.
Reproduction
visit https://bdevg.com/api/auth/signin then choose a sign with Github
Vercel function logs
The text was updated successfully, but these errors were encountered: