iOS/Swift/Firebase Authentication: Help Needed on Accessing “isNewUser”

拟墨画扇 提交于 2020-05-16 03:19:09

问题


In my iOS/Swift/Firebase app, I am trying to access the "isNewUser" parameter after a user successfully signs in via email/password so that I can pop a window to compel them to reset their password from the temporary one initially assigned upon user creation.

Any insights would be appreciated. Thanks.


回答1:


The .isNewUser method is available from the FirebaseAuth AdditionalUserInfo class. Here is the link. In order to utilize this code, please see a demo sign in function I wrote below.

Auth.auth().signIn(with: credential) { (result, error) in

        if let error = error{
            print("Error: \(error)");
            return;

        }

        //grabbing the user's ID info
        guard let uid = result?.user.uid else {return}

        //safely unwrap the boolean value rather than forcing it with "!" which could crash your app if a nil value is found
        guard let newUserStatus = result?.additionalUserInfo?.isNewUser else {return}
        //test the value in the debugger
        print("\nIs new user? \(newUserStatus)\n")



        if newUserStatus == true{
            //provide your alert prompt

        }
        else{
            //transition view to continue to the app
        }


    }


来源:https://stackoverflow.com/questions/53469092/ios-swift-firebase-authentication-help-needed-on-accessing-isnewuser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!