1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[firebase] cloud functionsが実行出来ない blocked by CORS policy

1
Posted at

背景

Firebaseで動かしてたサービスがcloud functionsへアクセスが出来なくなる問題に遭遇。
急にアクセス出来ないかつ心当たりなさすぎたのでハマった。一旦治ったのでまとめる

  1. cloud functions側でonCallのエンドポイントを作成。
functions.js
exports.func = functions.https.onCall((data) => {
    // ...
});
  1. クライアントからfirebase.onRequestで呼び出す。
client.js
functions.httpsCallable("func");

エラー内容

functions側のlogは出ない。そもそもapiを叩けていない状況

consoleを見るとなんか出てる
cors、、、君だったのか、いやいやでもonCallはcors出ないんじゃなかったの?(詳しくは加筆)

blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

解決法

こちらの記事の通り。
https://qiita.com/tekunikaruza_jp/items/c068506ca0d6d648cc50

簡単にまとめると権限のエラー

  1. gcpでcloud functions 該当の関数にアクセス
  2. 権限 > 追加でallusersにすれば良い。
    スクリーンショット 2022-09-28 21.08.32.png

元々allUsersを許容していた関数を作り直した際に権限がリセットされたことが原因?
とりあえず解決するのだが、allUsersってそもそも良いんだっけ?
もうちょっと調査する必要がありそう。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?