Android Code Snippet Firebase Authex - login mail/password SOLVED

Hi,

I share with you my code that allows you to enter a firebase with the email / password, avoiding errors that cannot be resolved in the library.
I hope you find it useful, if it is like as like like well.
To create a user and avoid fatal errors, we can do the following: When trying to create an account, you must first try to execute the signin to make sure that it does not exist, and in case there is to be able to analyze the errors and then determine what to do. We can do this with Logcat, according to the recent publication made by @Erel. https://www.b4x.com/android/forum/threads/parsing-your-apps-logs.107936/#content

this is my code

In this code, before executing the event UserCreated, I execute the SignedIn event, in order to validate that the user does not exist, in case it exists I can interpret the causes with logcat and make sure that when I execute the UserCreated event, it does not generate any errors.


It also contains some validations about the mail, which might not be necessary but I put them equally.

B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Public authex_created As FirebaseAuthEx
 Private Timer1 As Timer
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    
    Private Panel_EdiTextmail As Panel
    Private EditText_mail As EditText
    Private Panel_Editextpassword As Panel
    Private EditText_Password As EditText
    Private EditText_password2 As EditText
    Private Label_condiciones1 As Label
    Private Label_condiciones2 As Label
    Private Button_crear_cuenta As Button
    Private Panel_Editextpassword2 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("crear_cuenta")
    authex_created.Initialize("authex_created")
 Timer1.initialize("Timer1",500)

End Sub

Sub Activity_Resume
    Timer1.Enabled = True
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Timer1.Enabled = False
 
If UserClosed = True Then
StartActivity("login")
End If
End Sub


Sub Button_crear_cuenta_Click
 
    If EditText_Password.Text = EditText_password2.Text Then
    
        If EditText_Password.Text.Length <6 Then
        
        ToastMessageShow("Your password cannot be less than 6 digits",True)

        Else
        
        If EditText_mail.Text.Contains("@") Then
                If EditText_mail.Text.Contains(".") Then
                     If EditText_mail.Text.Contains("gmail") Then
                    ToastMessageShow("with a google account you must log in with that option",True)       
           Else
                   'valid if the user exists trying first to log me in normally

          
                    authex_created.SignInWithEmailAndPassword(EditText_mail.Text,EditText_Password.Text)
    
                    wait for authex_created_SignedIn (success As Boolean, User As FirebaseAuthUser, info As String)

                    If success Then
                    
                    ToastMessageShow("the user already exists, successfully entered",True)
                
                    If IsPaused(Main) = True Then CallSubDelayed(Main,"login_imagen")
 
                    End If
         End If
        Else
        ToastMessageShow("Your email address does not have the correct format",True)
        End If
    
    Else
        ToastMessageShow("Your email address does not have the correct format",True)
    
      End If
    
        End If
    
    Else
        ToastMessageShow("Passwords do not match", True)
    
    End If
 
End Sub


Sub Timer1_Tick
    Dim logs As String = Starter.LogBuffer.ToString
    If logs.Contains("The user may have been deleted") Then
        Try
' Only in this case can we create a new user
           authex_created.createUserWithEmailAndPassword(EditText_mail.Text,EditText_Password.Text)

        Catch
            Log(LastException)
        End Try
   
        ToastMessageShow("user created successfully", True)
        login.mail = EditText_mail.Text
        login.password =EditText_Password.Text
        StartActivity("login")
   
        Log("creacuenta_ logcat!")
        Starter.LogBuffer.Remove(0, Starter.LogBuffer.Length)
 
    Else
 
        If logs.Contains("The email address Is badly formatted") Then
            Log("login_ logcat!")
            ToastMessageShow("the format of your email address is incorrect", True)
            Starter.LogBuffer.Remove(0, Starter.LogBuffer.Length)
 
        Else
   
            If logs.Contains("The password is invalid") Then
                Log("login_ logcat!")
                ToastMessageShow("Your password is incorrect, try again", True)
                Starter.LogBuffer.Remove(0, Starter.LogBuffer.Length)
            End If
        End If
    End If
End Sub
 
Last edited:
Top