Has anyone successfully integrated the latest version of Auth.js into a production environment with Docker? I am currently utilizing the t3-stack (tRPC, Auth.JS, Prisma, Next.JS).
I attempted to upgrade to the beta version with the Prisma Adapter, but encountered an issue where signing in through any provider redirects to the Docker internal host, which is 0.0.0.0.
I'm unsure if this problem lies within Auth.js or Next.JS itself.
Setting the environment variables NEXTAUTH_URL
and/or AUTH_URL
to the production URL seems to correctly set the redirect URL on the provider page. However, after successfully signing in, the redirection still leads to 0.0.0.0.
(The application and authentication flow worked fine before upgrading to Auth.js)
In my Dockerfile, I've configured the following according to the official Next.JS documentation:
EXPOSE 3000
ENV PORT 3000
ENV HOSTNAME "0.0.0.0"
This is what my Auth.js configuration looks like:
export const {
handlers: { GET, POST },
auth,
} = NextAuth({
pages: {
signIn: "/auth/login",
error: "/auth/error",
signOut: "/auth/logout",
verifyRequest: "/auth/verify-request",
},
callbacks: {
signIn({ user, email }) {
// If email provider is used, only allow users with a specific email domain
if (email?.verificationRequest) {
return !isFakeEmail(user.email!, false);
}
return true;
},
session: ({ session, user }) => ({
...session,
user: {
...session.user,
id: user.id,
role: user.role,
subscribedTill: user.subscribedTill,
},
}),
},
adapter: PrismaAdapter(db),
providers: [
EmailProvider({
server: env.EMAIL_SERVER,
from: env.EMAIL_FROM,
maxAge: 5 * 60, // valid for 5 minutes
}),
DiscordProvider({ allowDangerousEmailAccountLinking: true }),
GitHubProvider({ allowDangerousEmailAccountLinking: true }),
],
trustHost: true, // Notice trustHost being set to true
});
I have experimented with different combinations of excluding NEXTAUTH_URL / AUTH_URL or using them together in my .env file.
Currently, setting
AUTH_URL="https://my-production-url.com/api/auth"
yields the described behavior (correct oauth redirect path, incorrect redirect upon successful oauth sign-in).
The package versions I am currently using are:
"@next-auth/prisma-adapter": "^1.0.7",
"next-auth": "^5.0.0-beta.15",
"next": "14.1.0",
Is there possibly a missing variable that could be causing this issue? I came across a related discussion on GitHub without a concrete solution: https://github.com/nextauthjs/next-auth/discussions/8449