Skip to content

Facebook Login Usage

Serhii Petrosyuk edited this page Apr 19, 2019 · 6 revisions

#

To log in with the Facebook account build a FacebookAuth object and call the signIn() method. Observe the auth result with any LifecycleOwner instance.

FacebookAuth.Builder(this)
    .requestEmail()
    .requestProfile()
    .enableSmartLock()
    .build()
    .signIn()
    .observe(this, Observer { authResult ->
        if (it.isSuccess) {
            // Do your further stuff with the [authResult.account] here
        } else {
            // Handle the [authResult.exception] here 
        }
    })

Call the enableSmartLock() if you want to use Smart Lock for Passwords on Android

Sign Out

With the FacebookAuth

Call the signOut() method in the FacebookAuth object. The observable value is Status

facebookAuth.logOut()
    .observe(this, Observer { status ->
        if (it.success) {
            // The user has been signed out
        } else {
            // Show the [status.message] if needed
            // Do your stuff on error 
        }
    })
SocialAuthManager.signOut(this).observe(this, Observer { status ->
    if (it.success) {
        // The user has been signed out
    } else {
        // Show the [status.message] if needed
        // Do your stuff on error 
    }
})
Clone this wiki locally