如何在GetStaticProps中获得AppCheck Token下一个JS
我需要将AppCheck令牌传递给我在GetStaticProps中的请求,但是当我使用getToken时(方法会丢弃下面的错误: appCheck在activate()被称为firebaseApp [默认]
之前使用AppCheck。 有什么方法可以在服务方面使用AppCheck令牌?
firebase.js:
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
const appCheck = firebase.appCheck();
appCheck.activate(process.env.NEXT_PUBLIC_APP_CHECK_SITE_KEY, true);
});
}
index.js:
export const getStaticProps = async () => {
let token
appCheck
.getToken(/* forceRefresh= */ false)
.then(async (rs) => {
token = rs.token;
})
.catch((err) => {
console.log(err);
});
const places = await getAllPlaces(token);
return { props: { places }, revalidate: 60 };
};```
I need to pass the appCheck token to my request in getStaticProps but when I use getToken( method it throws the error below:AppCheck is being used before activate() is called for FirebaseApp [DEFAULT]
Is there any way to use appCheck token in serve Side Rendering?
firebase.js:
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
const appCheck = firebase.appCheck();
appCheck.activate(process.env.NEXT_PUBLIC_APP_CHECK_SITE_KEY, true);
});
}
index.js:
export const getStaticProps = async () => {
let token
appCheck
.getToken(/* forceRefresh= */ false)
.then(async (rs) => {
token = rs.token;
})
.catch((err) => {
console.log(err);
});
const places = await getAllPlaces(token);
return { props: { places }, revalidate: 60 };
};```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这篇文章中有一个类似的问题可能会有所帮助: https://github.com/ vercel/next.js/讨论/35689 。
当前,我认为使用应用程序检查与服务器端渲染是不可能的,这可能是因为应用程序检查与客户端浏览器而不是服务器的交互。
这只是一个理论,但是从文档中拾取,我认为应用程序检查至少需要对客户的访问。
There's a similar issue in this post that may be helpful: https://github.com/vercel/next.js/discussions/35689.
Currently, I don't think using App Check with Server Side Rendering is possible, likely because App Check interacts with the client browser and not the server.
That's only a theory, but picking up from the docs, I think App Check requires at least some access to the client.
https://firebase.google.com/docs/app-check/web/recaptcha-provider?hl=en