Deployed (Vercel) NextJS application with NextAuth.js goes to 404 pages on any of the auth api routes (/api/auth) #2670
-
Description 🐜Hi. Basically I have a NextJS app that uses NextAuth.js for authentication. On localhost environment, everything works great, but on the deployed application (Vercel) all of the auth api routes are not found and redirect to 404. Is this a bug in your own project?Yes How to reproduce ☕️This is my [...nextauth].js file. import NextAuth from 'next-auth';
import Providers from 'next-auth/providers';
import { redirect } from 'next/dist/next-server/server/api-utils';
import { extractUser } from '../../../lib/api-helpers';
export default NextAuth({
site: process.env.API_URL,
pages: {
signIn: '/auth/signin',
},
providers: [
Providers.Credentials({
// The name to display on the sign in form (e.g. 'Sign in with...')
name: 'Credentials',
async authorize(credentials, req) {
const res = await fetch(`${process.env.API_URL}/api/auth/signin-api`, {
method: 'POST',
body: JSON.stringify(credentials),
headers: { 'Content-Type': 'application/json' },
});
const user = await res.json();
// If no error and we have user data, return it
if (res.ok && user) {
return Promise.resolve(user);
}
return Promise.resolve(null);
},
}),
],
database: process.env.MONGODB_URI,
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
},
callbacks: {
async signIn(user, account, profile) {
return Promise.resolve(true);
},
async redirect(url, baseUrl) {
return baseUrl;
},
async jwt(token, user, account, profile, isNewUser) {
const extractedUser = extractUser(user);
token = {
...token,
...extractedUser,
};
return Promise.resolve(token);
},
async session(session, user) {
session.user = extractUser(user);
return Promise.resolve(session);
},
},
}); These are my environment varibles:
Screenshots / Logs 📽No response Environment 🖥Binaries: Contributing 🙌🏽No, I am afraid I cannot help regarding this |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
You don't need to set this env variable in case of Vercel. I also suggest looking at old issued/discussions, thus has been asked multiple times. |
Beta Was this translation helpful? Give feedback.
-
Can you point me towards a post regarding this issue? I can't find it on the issues page. |
Beta Was this translation helpful? Give feedback.
-
will need a reproduction to be able to help further. |
Beta Was this translation helpful? Give feedback.
You don't need to set this env variable in case of Vercel. I also suggest looking at old issued/discussions, thus has been asked multiple times.