Advertisement
uwong15

Untitled

May 28th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.60 KB | None | 0 0
  1. val mAuth: FirebaseAuth = FirebaseAuth.getInstance()
  2. mAuth.signInWithCredential(credential).addOnCompleteListener { task ->
  3.                 if(task.isSuccessful){
  4.                     mAuth.currentUser?.let {
  5.                         it.getIdToken(true)
  6.                             .addOnCompleteListener { task2 ->
  7.                                 task2.getResult()?.let {
  8.                                     it.token?.let {
  9.                                         progress_layout.visibility = LinearLayout.VISIBLE
  10.  
  11.                                         Log.d("login", "signInWithCredential:success")
  12.  
  13.                                         val user = mAuth.currentUser
  14.  
  15.                                         var googleData = FacebookUserNoUser()
  16.  
  17.                                         var accountData = DataUserFacebook()
  18.                                         user?.let {
  19.                                             accountData.uid = user.uid
  20.                                             accountData.name = user.displayName
  21.                                             accountData.email = user.email
  22.                                             accountData.phone = user.phoneNumber
  23.                                         }
  24.  
  25. //                                        googleData.installationId = serial
  26.                                         sp.getString(Argument.INSTANCE_ID, "")?.let {
  27.                                             googleData.instanceId = it
  28.                                         } ?: run {
  29.                                             googleData.instanceId = ""
  30.                                         }
  31.                                         googleData.firebaseIdToken = it
  32.                                         googleData.nickName = ""
  33.                                         googleData.user = accountData
  34.                                         googleData.provider = 3
  35.  
  36.                                         Log.d("main", "GOOGLE DATA " + Gson().toJson(googleData))
  37.  
  38.                                         Toast.makeText(this, "Login success", Toast.LENGTH_SHORT).show()
  39.                                     } ?: run {
  40.                                         Toast.makeText(this, "Cannot get token from google authorization", Toast.LENGHT_SHORT).show()
  41.                                     }
  42.                                 } ?: run {
  43.                                     Toast.makeText(this, "Cannot get result after login with google", Toast.LENGTH_SHORT).show()
  44.                                 }
  45.                             }
  46.                         }
  47.                     }
  48.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement