我正在嘗試為用戶設定一個按鈕,以通過 Stripe 客戶門戶及其 Firebase 的集成來管理他的訂閱。
問題,該檔案對舊版本的 Firebase (8) 有效,而我使用的是新版本 Firebase 9。
我們在客戶端,這是 React.js。
這是他們呼叫函式的js代碼(你可以在這里看到完整的代碼:https : //github.com/stripe-samples/firebase-subscription-payments/blob/master/public/javascript/app.js):
const functionLocation = 'us-east1';
const functionRef = firebase
.app()
.functions(functionLocation)
.httpsCallable('ext-firestore-stripe-subscriptions-createPortalLink');
const { data } = await functionRef({ returnUrl: window.location.origin });
window.location.assign(data.url);
});
使用 Firebase 9,它應該是這樣的:
const functions = getFunctions(firebaseApp)
export async function goToBillingPortal() {
const functionRef = httpsCallable(functions, 'ext-firestore-stripe-subscriptions-createPortalLink');
const { data } = await functionRef({ returnUrl: window.location.origin });
window.location.assign(data.url);
}
控制臺顯示 3 個錯誤:
Access to fetch at 'https://us-central1-xxxxxxxxd76.cloudfunctions.net/ext-firestore-stripe-subscriptions-createPortalLink' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
service.ts:206 POST https://us-central1-xxxxxxx76.cloudfunctions.net/ext-firestore-stripe-subscriptions-createPortalLink net::ERR_FAILED
Uncaught (in promise) FirebaseError: internal
顯然,問題是我需要指定服務器的位置(例如 us-central1),但我無法理解如何使用 Firebase 9。所有指南均適用于 Firebase 8。
我嘗試過不同的事情,例如:
const functions = getFunctions(firebaseApp).location("us-central1")
或者
const functionRef = httpsCallable(functions, 'ext-firestore-stripe-subscriptions-createPortalLink').location("us-central1")
但它不起作用。
想法?
uj5u.com熱心網友回復:
如圖這里在檔案中,則應該通過的區域作為第二個引數getFunctions()的方法:
const functions = getFunctions(firebaseApp, "europe-west1");
uj5u.com熱心網友回復:
還可以定義使用 部署的位置.region(),我認為它甚至可以接受一個串列:
const CLOUD_FUNCTIONS_REGION = "us-east1";
exports.billing_portal = functions.region( CLOUD_FUNCTIONS_REGION ).https.onCall(
async (data, context: CallableContext) => {
}
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/365189.html
標籤:javascript 节点.js 火力基地 谷歌云功能 条纹支付
上一篇:相鄰的JSX元素必須包含在封閉標簽中。你想要一個JSX片段<>...</>嗎?
下一篇:僅在單擊事件時洗掉輪廓
