1
0

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][iOS] reauthenticate しないと request.auth.toke.email_verified が更新されなかった

1
Last updated at Posted at 2021-12-10

要するに:
Auth.auth().createUser()後に
Auth.auth().currentUser?.sendEmailVerification()でメール認証した後は、
Auth.auth().currentUser?.reload()
Auth.auth().currentUser?.reauthenticate()の両方をしておいた方が良い。


コード形式の方が分かりやすそうなので、↓の様に書きます。

swift
// 1. ユーザー作成
Auth.auth().createUser()

// 2. 認証メールを送信
user.sendEmailVerification()

// 3. メールに記載のリンクをクリック
// 4. クラウド側の email_verified が true になる

// 5. currentUser の isEmailVerified は false のまま
Auth.auth().currentUser?.isEmailVerified // false

// 6. currentUser の isEmailVerified を更新
Auth.auth().currentUser?.reload()
Auth.auth().currentUser?.isEmailVerified // true

// 7. データを作成しようとする
//      request.auth.toke.email_verified が false になってる!
//      セキュリティールールで
//      request.auth.token.email_verified == true
//      してると、 Permission denied になってしまう
Firestore.firestore().collection("users").document("hoge").setData(["name": "fuga"])

// 8. 再認証
Auth.auth().currentUser?.reauthenticate()

// 9. データ作成
//      request.auth.toke.email_verified は true になってる!
Firestore.firestore().collection("users").document("hoge").setData(["name": "fuga"])
1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?