good night, I managed to create my first login in my application with kotlin, at the moment every time the app opens it asks you to log in, I would like to know how to do that when the user is logged in, it does not ask to log in again and finally the session closing so that now if the user asks to register again. This is my code:
package com.example.orashopboss
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.GoogleAuthProvider
import kotlinx.android.synthetic.main.activity_main.*
enum class ProviderType {
BASIC
}
class Login : AppCompatActivity() {
private val mAuth : FirebaseAuth by lazy { FirebaseAuth.getInstance() }
override fun onCreate(savedInstanceState : Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
signIn.setOnClickListener {
val email = editTextEmailLog.text.toString()
val password = editTextPassLog.text.toString()
if (isValidEmailAndPassword(email , password)) {
signUpByEmail(email , password)
} else {
val intent = Intent(this , popUpWndow::class.java)
startActivity(intent)
}
}
}
private fun signUpByEmail(email : String , password : String) {
mAuth.signInWithEmailAndPassword(email , password).addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
if (mAuth.currentUser!!.isEmailVerified) {
val intent = Intent(this , home::class.java)
startActivity(intent)
} else {
val intent = Intent(this , emailnoverified::class.java)
startActivity(intent)
}
}
}
}
private fun isValidEmailAndPassword(email : String , password : String): Boolean {
return !email.isNullOrEmpty() &&
!password.isNullOrEmpty()
}
}
Thank you and good night!