swift 列表按钮中的 Firebase 用户注销

Firebase User signOut in swift list button

我正在尝试在我的列表视图中设置一个按钮,以允许用户从设备上注销他们的帐户。我按照有关设置登录和注销的视频进行操作,我对这些很有信心,但我不确定自己做错了什么。

这是我的代码:

struct SettingsAccountView: View {
    @EnvironmentObject var session: SessionStore

    func getUser() {
        session.listen()
    }

    var body: some View {
        List {
            Section {
                Button(action: {
                    print("Change USER email")
                            }) {
                    SettingsCell(title: "Change Email", imgName: "envelope.fill", clr: Color("Waterfall"))
                }

                Button(action: {
                    print("Change USER password")
                                    }) {
                    SettingsCell(title: "Change Password", imgName: "eye.slash.fill", clr: Color("Waterfall"))
                }

                Button(action: {
                    print("Change USER Photo")
                            }) {
                    SettingsCell(title: "Change Profile Photo", imgName: "camera.rotate", clr: Color("Waterfall"))
                }
            }

            Section {
                Button(action: session.signOut) {
                    print("SignOut")
                }) {
                    SettingsCell(title: "Sign Out", imgName: "person.crop.circle.badge.xmark", clr: .red)
                }
                Button(action: {
                    print("Delete MY Account")
                            }) {
                    SettingsCell(title: "Delete My Account", imgName: "trash.circle", clr: .red)
                }
            }

        }.listStyle(GroupedListStyle())
            .environment(\.horizontalSizeClass, .regular)
            .navigationBarTitle("Account", displayMode: .inline)
    }
}

struct SettingsAccountView_Previews: PreviewProvider {
    static var previews: some View {
        SettingsAccountView()
    }
}

这可能是您错误地为此按钮指定了 action 参数的问题:

Button(action: session.signOut) {
    print("SignOut")
}) {
    SettingsCell(title: "Sign Out", imgName: "person.crop.circle.badge.xmark", clr: .red)
}

您似乎添加了一个额外的闭包作为操作块。您的操作参数可以是函数(如 session.signOut)或闭包(如 { print("SignOut") })。不可能是他们两个。

试试这个代码:

Button(action: {
    self.session.signOut
    print("SignOut")
}) {
    SettingsCell(title: "Sign Out", imgName: "person.crop.circle.badge.xmark", clr: .red)
}