要するに:
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"])