You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Next.js ISR预渲染失败 提示Firebase权限不足问题求助

Next.js ISR页面Firebase权限不足报错排查

问题现象

Web应用内的ISR页面无法正常渲染,抛出Firebase权限不足报错,但单独测试对应权限时功能完全正常,无法定位问题原因。

当前Firestore安全规则配置

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /blogs/{blog} {
      allow read, get;
      allow write, update, create, delete: if (request.auth.uid == "R3tc0RKCDgX8yhaHS5c0Ej3IXxF3");
    }
    match /forum/{forum} {
      allow read, get;
      allow write, create, update, delete: if (request.auth.uid == "R3tc0RKCDgX8yhaHS5c0Ej3IXxF3");
    }
    match /forum/{forum}/messages/{messages} {
        allow read, get;
      allow write, create, update, delete: if (request.auth.uid != null);
    }
    match /chats/{room} {
        allow write, read, get, create, update, delete: if request.auth.uid == get(/databases/$(database)/documents/chats/$(room)).data.uid[0] || request.auth.uid == get(/databases/$(database)/documents/chats/$(room)).data.uid[1];
    }
    match /chats/{room}/messages/{messages} {
        allow write, read, get, create, update, delete: if request.auth.uid == get(/databases/$(database)/documents/chats/$(room)).data.uid[0] || request.auth.uid == get(/databases/$(database)/documents/chats/$(room)).data.uid[1];
    }
  }
}

问题页getStaticPaths实现代码

export async function getStaticPaths() {
  let array = [];

  await getDocs(collection(firestore, "forum")).then((res) => {
    array = res.docs.map((data) => {
      const { id } = data.data();

      return {
        params: { question: id },
      };
    });
  });

  return {
    paths: array,
    fallback: "blocking",
  };
}

已完成测试验证

  • Firebase规则Playground全场景测试权限逻辑正常
  • 页面切换为SSR(服务端渲染)模式时,数据获取逻辑无异常
  • 仅在Next.js ISR(增量静态再生)运行场景下,Firestore请求触发权限不足报错

内容的提问来源于stack exchange,提问作者Ibraheem Haseeb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 19:15:38