iOS/Swift/Firebase身份验证:访问"isNewUser"时需要帮助 [英] iOS/Swift/Firebase Authentication: Help Needed on Accessing "isNewUser"

查看:52
本文介绍了iOS/Swift/Firebase身份验证:访问"isNewUser"时需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的iOS/Swift/Firebase应用程序中,我试图在用户通过电子邮件/密码成功登录后访问"isNewUser"参数,以便我可以弹出一个窗口来强迫他们从临时密码中重置密码.最初是在用户创建时分配的.

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.

推荐答案

可从FirebaseAuth AdditionalUserInfo类获得 .isNewUser 方法.这里是链接.为了使用此代码,请参阅我在下面编写的演示登录功能.

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
        }


    }

这篇关于iOS/Swift/Firebase身份验证:访问"isNewUser"时需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆