NextAuth url?error=callback on production but working on localhost:3000/ #2243
Replies: 16 comments 10 replies
-
did you ever fix this? facing same issue :'( |
Beta Was this translation helpful? Give feedback.
-
Hard to do anything without reproduction. You can see a working google example here: https://next-auth-example.vercel.app/ So most probably a user misconfiguration. |
Beta Was this translation helpful? Give feedback.
-
I'm facing the same issue, did you guys figure out what was the problem? I checked the configs in Vercel, Google, Code everywhere. I couldn't figure it out. |
Beta Was this translation helpful? Give feedback.
-
I'm using nextjs, next-auth, vercel, google provider and only on production I can't sign in to google. I can't figure out the issue. Has anyone found a solution? |
Beta Was this translation helpful? Give feedback.
-
Like someone mentioned above, quite hard to assist without reproduction. However, some of the issues/mistakes that I've faced with that setup were:
|
Beta Was this translation helpful? Give feedback.
-
Same issue here, working fine on localhost:3000 but not in local production build. Context:
/pages/api/auth/[...nextauth].js: import NextAuth from "next-auth";
import GithubProvider from "next-auth/providers/github"
import CredentialsProvider from "next-auth/providers/credentials";
const BASE_URL = process.env.NEXT_PUBLIC_BASE_URL;
const SAVE_TOKEN = process.env.NEXT_PUBLIC_SAVE_TOKEN;
export const authOptions = {
providers: [
CredentialsProvider({
name: 'Credentials',
credentials: {
password: { label: "Password", type: "password" }
},
async authorize(credentials, req) {
const res = await fetch(`${BASE_URL}/api/login`, {
method: 'POST',
body: JSON.stringify(credentials),
headers: {
"Content-Type": "application/json",
'Authorization': `Bearer ${SAVE_TOKEN}`
}
})
const user = await res.json()
if (res.ok && user) {
return user
}
return null
}
})
],
callbacks: {
async signIn({user, account, profile, email, credentials}){
const isAllowed = true;
if (isAllowed){
return true
} else {
return '/editor/unauthorized'
}
},
async redirect({ur, baseUrl}){
return '/editor'
}
}
}
export default NextAuth(authOptions) callbacks.signIn() executes in dev mode, not in prod build, same thing with callbacks.redirect() Here's dashboard.js, where I'm trying to get a user signed in: import { SignIn, SignOut } from "./actions";
import { getServerSession } from "next-auth";
import { authOptions } from "@/pages/api/auth/[...nextauth]"
export const dynamic = 'force-dynamic';
export default async function EditorMainPage() {
let session;
const [sessionRes] = await Promise.allSettled([getServerSession(authOptions)]);
if (sessionRes.status === "fulfilled") {
session = sessionRes.value;
} else {
console.error(sessionRes);
}
return (
<div>
{session ? <SignOut /> : <SignIn />}
</div>
)
} actions.js: 'use client';
import { signIn, signOut } from 'next-auth/react';
export function SignOut() {
return (
<button onClick={() => signOut()}>
→ Sign out
</button>
);
}
export function SignIn() {
return (
<button onClick={() => signIn()}>
<div>Sign in</div>
</button>
);
} and these are the requests headers I'm getting in prod build only: ` Request URL: http://localhost:3000/api/auth/error?error=fetch%20failed |
Beta Was this translation helpful? Give feedback.
-
I'm facing the same issue. Has anyone find any solution for this ? |
Beta Was this translation helpful? Give feedback.
-
Same issue here :( |
Beta Was this translation helpful? Give feedback.
-
Same issue here. But until a couple of days ago everything was working smoothly. How is this even possible? |
Beta Was this translation helpful? Give feedback.
-
I ran into this error before I added updated my environment variables on production. |
Beta Was this translation helpful? Give feedback.
-
If you deploy from Vercel it overrides the environment variables defined within the UI with the file. I'd be careful with .env or .env.local too. |
Beta Was this translation helpful? Give feedback.
-
There are several things to consider when deploying from local to production:
|
Beta Was this translation helpful? Give feedback.
-
Same issue here. In localhost everything is working smoothly. How is this even possible? |
Beta Was this translation helpful? Give feedback.
-
I had the same issue, getting Now I'm not getting an error anymore, but after sign in I'm redirected to my "/" page instead of the one used in the signIn function
Anyone have an idea why the sign in doesn't redirect to my |
Beta Was this translation helpful? Give feedback.
-
In mine case the issue was related to wrong postinstall script for prisma,
Then I just updated my postinstall script |
Beta Was this translation helpful? Give feedback.
-
In my case I've wrongly copied the development credentials instead of production credentials. Remember that you should have separate credentials for development (http://localhost:3000) and production, so be aware of copy the correct one. On the other side, I'm not sure in which level this errors messages can be improved to facilitate. |
Beta Was this translation helpful? Give feedback.
-
My development next auth google provider is working but on production (vercel) is gives an error=callback.
On production, I m still able to login with credentials but not with google provider
Beta Was this translation helpful? Give feedback.
All reactions