最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google OAuth Configuration on Live Server - Stack Overflow

programmeradmin11浏览0评论

js setup and I used next auth(Google OAuth) before publishing it to production it Google OAuth is perfectly working on local host, however when I tried to upload it on OVH VPS it always says after clicking the login it redirect me to ? and display the error below

Server error There is a problem with the server configuration.

Check the server logs for more information.

the current code that I have is for login for

import Image from "next/image";
import Link from "next/link";
import { FcGoogle } from "react-icons/fc";
import "./loginform.css";
import { auth, signIn } from "@/auth";

const LoginForm = async () => {
  const session = await auth();
  return (
    <div className="login-wrapper">
      <div className="login-container">
        <Image
          src={"/images/logo.png"}
          alt="logo"
          width={300}
          height={300}
          className="logo"
        />
        <h1 className="login-title">Welcome Back</h1>
        {session?.user ? (
          <div className="logged-in-content">
            <p>
              You are already logged in as <span>{session.user.email}</span>
            </p>
            <Link href="/dashboard" className="dashboard-button">
              Go to Dashboard
            </Link>
          </div>
        ) : (
          <form
            className="social-button google-button"
            action={async () => {
              "use server";
              try {
                await signIn("google");
              } catch (error: unknown) {
                if (
                  (error as { digest?: string })?.digest?.includes(
                    "NEXT_REDIRECT"
                  )
                ) {
                  throw error;
                }
                console.error("Login error:", error);
                throw error;
              }
            }}
          >
            <FcGoogle size={24} />
            <button type="submit">Login with Google</button>
          </form>
        )}
      </div>
    </div>
  );
};

export default LoginForm;

and on the auth.ts setup I have this following codes

import NextAuth from "next-auth";
import Google from "next-auth/providers/google";

if (!process.env.AUTH_GOOGLE_ID || !process.env.AUTH_GOOGLE_SECRET) {
  throw new Error("Missing Google OAuth credentials");
}

const allowedEmails = process.env.NEXT_PUBLIC_ALLOWED_EMAILS?.split(",") || [];

export const { handlers, auth, signIn, signOut } = NextAuth({
  providers: [
    Google({
      clientId: process.env.AUTH_GOOGLE_ID,
      clientSecret: process.env.AUTH_GOOGLE_SECRET,
    }),
  ],
  callbacks: {
    async signIn({ profile }) {
      try {
        if (!profile?.email) return false;
        return allowedEmails.includes(profile.email);
      } catch (error) {
        console.error("Sign-in error:", error);
        return false;
      }
    },
  },
  secret: process.env.AUTH_SECRET,
});

Thank you so much

发布评论

评论列表(0)

  1. 暂无评论