I am trying to authenticate users via verification code sent to their emails after the submitting details for sign up.
I have the following code to listen to the code/pin as received via the email but am not sure if I am adding the header/bearer-token the right way as I receive server error on verification.
Kindly assist
var codeEntered:String? = null
txt_pin_entry.setOnPinEnteredListener {
codeEntered = "$it"
Toast.makeText(context!!.applicationContext, "inside $codeEntered", Toast.LENGTH_SHORT).show()
}
submitBtn.setOnClickListener {
val url = "https://fathomless-badlands-69782.herokuapp.com/api/auth/verify"
val params = HashMap<String, String?>()
params["Authorization"] = "Bearer $tokenCode"
params["code"] = codeEntered
Toast.makeText(context!!.applicationContext, "outside $codeEntered", Toast.LENGTH_SHORT).show()
val jsonObject = JSONObject(params as Map<*, *>)
val request = JsonObjectRequest(Request.Method.PUT, url, jsonObject,
Response.Listener { response ->
try{
Log.i("Registration", "Response $response")
}catch (e: Exception){
Log.e("Registration", "Response $e")
Toast.makeText(context!!.applicationContext, "Response $response", Toast.LENGTH_SHORT).show()
}
}, Response.ErrorListener {
Log.e("Registration", "Response $it")
Toast.makeText(context!!.applicationContext, "Response $it", Toast.LENGTH_SHORT).show()
})
VolleySingleton.getInstance(context!!.applicationContext).addToRequestQueue(request)
val actionToVerificationResult = CodeVerificationFragmentDirections.actionToVerificationResult()
Navigation.findNavController(it).navigate(actionToVerificationResult)
}
}
The API expects a request as below
{
code: String
}