Firebase kicks out current user

前端 未结 14 1798
一个人的身影
一个人的身影 2020-11-22 01:42

So I have this issue where every time I add a new user account, it kicks out the current user that is already signed in. I read the firebase api and it said that \"I

14条回答
  •  花落未央
    2020-11-22 02:07

    Update for Swift 4

    I have tried a few different options to create multiple users from a single account, but this is by far the best and easiest solution.

    Original answer by Nico

    First Configure firebase in your AppDelegate.swift file

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        FirebaseApp.configure()
        FirebaseApp.configure(name: "CreatingUsersApp", options: FirebaseApp.app()!.options)
    
        return true
    }
    

    Add the following code to action where you are creating the accounts.

                if let secondaryApp = FirebaseApp.app(name: "CreatingUsersApp") {
                    let secondaryAppAuth = Auth.auth(app: secondaryApp)
                    
                    // Create user in secondary app.
                    secondaryAppAuth.createUser(withEmail: email, password: password) { (user, error) in
                        if error != nil {
                            print(error!)
                        } else {
                            //Print created users email.
                            print(user!.email!)
                            
                            //Print current logged in users email.
                            print(Auth.auth().currentUser?.email ?? "default")
                            
                            try! secondaryAppAuth.signOut()
                            
                        }
                    }
                }
            }
    

提交回复
热议问题