Auth Module

First you need to import and instantiate PRIVO auth module:

  import com.privo.sdk.PrivoAuth

You can instantiate the PRIVO auth module with Context:

  val auth = PrivoAuth(this)

Functionality:
auth.getToken() - returns a previously issued token, if it hasn't expired. Can return null if token wasn't issued or expired

  auth.renewToken { status ->
    setTokenText(status?.token)
  }

Renew token. Return token and it's status

  auth.showLogin { token ->
    setTokenText(token)
  }

Shows a modal window. User is prompted to Sign In inside this modal window.

   auth.showRegister { dialog ->
     dialog.hide()
   }

Shows a modal window. User is prompted to Create an Account inside this modal window.
NOTE: this dialog should be closed from completion callback. (This can be done after a short delay. In this case, the user will be able to read content of the congratulations page.)

auth.logout() - Logout and clean previously issued token.

Auth Module Usage Example:

class AuthActivity : AppCompatActivity() {
        private lateinit var binding: ActivityAuthBinding
        private lateinit var auth: PrivoAuth
        private lateinit var loadingDialog: LoadingDialog

        override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          auth = PrivoAuth(this)
          loadingDialog = LoadingDialog(this)
          binding = ActivityAuthBinding.inflate(layoutInflater)
          val view = binding.root
          setContentView(view)
          initViews()
        }
        private fun initViews() {
          binding.registerButton.setOnClickListener {
            auth.showRegister { dialog ->
                val handler = Handler(Looper.getMainLooper())
                handler.postDelayed({
                    dialog.hide()
                }, 5000)
            }
          }
          binding.signInButton.setOnClickListener {
            auth.showLogin { token ->
                setTokenText(token)
            }
          }
          binding.getTokenButton.setOnClickListener {
            val token = auth.getToken()
            setTokenText(token)
          }
          binding.renewTokenButton.setOnClickListener {
            loadingDialog.show()
            setTokenText(null)
            auth.renewToken { status ->
                loadingDialog.hide()
                setTokenText(status?.token)
            }
          }
          binding.logoutButton.setOnClickListener {
            auth.logout()
            setTokenText(null)
          }
        }
        fun setTokenText(token: String?) {
          binding.tokenView.text = "Token: ${token ?: "Empty"}"
        }
      }