首页 > 解决方案 > iOS/Swift/Firebase 身份验证:访问“isNewUser”需要帮助

问题描述

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

任何见解将不胜感激。谢谢。

标签: iosswiftfirebase-authentication

解决方案


Bool可.isNewUser从 FirebaseAuth AdditionalUserInfo 类获得。 这是链接。为了使用此代码,请查看我在下面编写的演示登录功能。

Auth.auth().signIn(with: credential) { (result, error) in
        
        if let error = error {
            print("Error: \(error)");
            return;
            
        }
        
        // Fetch the user's 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
        print("\nIs new user? \(newUserStatus)\n")
        
        if newUserStatus == true {
            // Provide your alert prompt

        }
        else{
            // Transition view to continue into the app

        }
    }

推荐阅读