【发布时间】:2017-03-27 10:48:23
【问题描述】:
一些背景
创建用户帐户后,我使用回调链按顺序 1 > 2 > 3 做 3 件事。
在 Firebase Auth 中创建用户(使用
createUser(withEmail ...)的标准方式)我将用户的个人资料图片上传到 Firebase 存储并捕获返回的
downloadUrl以用于第 3 步我将用户的其他信息(包括步骤 2 中的
downloadUrl)存储在实时数据库的一个节点中(由$userid键入)
现在的问题
我提供了一个名为“删除帐户”的按钮,可以让用户删除所有内容。也就是说,清除他们在实时数据库中的所有数据,清除他们在 Firebase 存储中的个人资料图片,最后从 Auth 中删除他们的帐户。 重要的是,所有这些操作都应该成功,或者即使有一个失败也应该取消。
我已经浏览了大约 10 页的 S/O 问题和答案,其中有 1 个 unanswered question 像这样(它询问了帐户创建过程......我想这个问题的答案很容易适应在这里。)
我尝试了什么?
目前,我像这样使用回调链:
// start by atomically deleting all the user data from the Realtime Database using the fanout system.
- get all appropriate locations and save in fanout dictionary
- update all these locations to nil // atomic goodness :)
-callback:
-on failure:
- just return // no worries, nothing has changed yet :/
-on success:
// proceed to delete user files on firebase storage
- delete path $userid on firebase storage
-callback:
-on failure: // this is bad, no idea what to do :(
-on success:
// proceed to delete account from Auth
- delete user account from Auth
-callback:
-on failure: // this is terrible, also, it could happen often b/c firebase does ask for re-authentication sometimes :(
-on success: // thank goodness! I have an authListener somewhere ready to show the 'signInViewController' :)
您如何以原子方式处理此类多系统(Auth、Storage、RealtimeDB)操作?我已经研究了 transactions,但看不到它们如何适用于此 - 文档仅显示它们用于在 RealtimeDB 中增加喜欢/星等的计数器。
任何帮助将不胜感激。
【问题讨论】:
标签: swift firebase firebase-realtime-database firebase-authentication firebase-storage