I’m a beginner tiring to develop a app in kotlin using laravel/sanctum api.
Right now i stock in login, because all time that i try to call
LARAVEL_URL ="http://10.0.2.2/venturiAPI/public/api/login"
MainActivity.kt
mServiceV.login(email,password,deviceName).enqueue(object : Callback<String>{
override fun onResponse(call: Call<String>, response: Response<String>) {
Log.d("ErrorBody response", response.errorBody().toString())
Log.d("Body response", response.body().toString())
Log.d("Raw response", response.raw().toString())
Log.d("message response", response.message())
Log.d("Headers response", response.headers().toString())
Log.d("Succes response", response.isSuccessful.toString())
Log.d("code response", response.code().toString())
Log.d("token", GlobalVar.MyT.toString() )
GlobalVar.MyT = response.body()
startActivity(Intent([email protected], MagazzinoActivity::class.java))
}
override fun onFailure(call: Call<String>, t: Throwable) {
Toast.makeText([email protected], t.message!!, Toast.LENGTH_SHORT).show()
}
})
}
android studio Logcat
2021-01-20 13:25:29.868 23188-23188/com.example.gestionaleventuri D/ErrorBody response: [email protected]
2021-01-20 13:25:29.868 23188-23188/com.example.gestionaleventuri D/Body response: null
2021-01-20 13:25:29.868 23188-23188/com.example.gestionaleventuri D/Raw response: Response{protocol=http/1.1, code=401, message=Unauthorized, url=http://10.0.2.2/venturiAPI/public/api/login}
2021-01-20 13:25:29.869 23188-23188/com.example.gestionaleventuri D/message response: Unauthorized
2021-01-20 13:25:29.869 23188-23188/com.example.gestionaleventuri D/Headers response: Date: Wed, 20 Jan 2021 12:25:30 GMT
Server: Apache/2.4.41 (Win64) PHP/7.3.12
X-Powered-By: PHP/7.3.12
Cache-Control: no-cache, private
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 57
Access-Control-Allow-Origin: *
Content-Length: 47
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/json
2021-01-20 13:25:29.869 23188-23188/com.example.gestionaleventuri D/Succes response: false
2021-01-20 13:25:29.869 23188-23188/com.example.gestionaleventuri D/code response: 401
laravel.log retrive
local.ERROR: Route [login] not defined. {"exception":"[object] (SymfonyComponentRoutingExceptionRouteNotFoundException(code: 0): Route [login] not defined. at C:wamp64wwwventuriAPIvendorlaravelframeworksrcIlluminateRoutingUrlGenerator.php:429)
when i test API using Postman everything works fine
http://127.0.0.1/venturiAPI/public/api/login
and the response retrive the generated token
api.php
Route::post('login', [UserController::class, 'index']); //works only on PostMan
Route::get('listProduct',[ProductController::class,'index']); //works everywhere
Route::group(['middleware' => 'auth:sanctum'], function(){
Route::get('activeOrders',[ReservationController::class,'activeOrder']);
});
am i missing some sanctum configuration?
because if i call other endpoints that don’t require token everything works
Source: Android Questions