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

node.js - TypeError: (0 , _next_auth_firebase_adapter__WEBPACK_IMPORTED_MODULE_2__.default) is not a function - Stack Overflow

programmeradmin4浏览0评论

Receiving this error whenever i run npm run dev.

Full error:

⨯ TypeError: (0 , _next_auth_firebase_adapter__WEBPACK_IMPORTED_MODULE_2__.default) is not a function
    at admin (c:\Users\user\Downloads\Muscat\src\pages\api\auth\[...nextauth].js:47:27)
  45 |     }),
  46 |   ],
> 47 |   adapter: FirebaseAdapter(admin.firestore()),
     |                           ^
  48 |   callbacks: {
  49 |     async session({ session, user }) {
  50 |       session.user.id = user.id;

Tried to uninstall using commands and reinstall but issue still persists.

Command used for uninstallation: npm uninstall @next-auth/firebase-adapter

Command used for reinstallation: npm install @next-auth/firebase-adapter

FULL CODE:

import NextAuth from "next-auth";
import GoogleProvider from "next-auth/providers/google";
import FirebaseAdapter from "@next-auth/firebase-adapter";
import { cert } from "firebase-admin/app";
import admin from "firebase-admin";

// Get the raw env variable
const rawServiceAccount = process.env.FIREBASE_ADMIN_CREDENTIALS;

// Debug: Check if the variable is set
console.log("RAW ADMIN CREDS:", rawServiceAccount);

if (!rawServiceAccount) {
  throw new Error("FIREBASE_ADMIN_CREDENTIALS is missing! Check your .env.local.");
}

// Parse JSON safely
let serviceAccount;
try {
  serviceAccount = JSON.parse(rawServiceAccount);
} catch (error) {
  throw new Error("FIREBASE_ADMIN_CREDENTIALS is not valid JSON. Check .env.local formatting.");
}

// Debug: Ensure private key is correctly formatted
if (!serviceAccount.private_key) {
  throw new Error("Parsed FIREBASE_ADMIN_CREDENTIALS does not contain a private_key.");
}

// Ensure private_key newlines are properly formatted
serviceAccount.private_key = serviceAccount.private_key.replace(/\\n/g, "\n");

// Initialize Firebase Admin
if (!admin.apps.length) {
  admin.initializeApp({
    credential: cert(serviceAccount),
  });
}

export default NextAuth({
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
    }),
  ],
  adapter: FirebaseAdapter(admin.firestore()),
  callbacks: {
    async session({ session, user }) {
      session.user.id = user.id;
      return session;
    },
  },
});

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论