So I have removed all laravel 5.5 oringinal auth stuff so my Auth\LoginController now looks like this:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Tymon\JWTAuth\Facades\JWTAuth;
use Tymon\JWTAuth\Exceptions\JWTException;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
*/
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function authenticate(Request $request)
{
// grab credentials from the request
$credentials = $request->only('email', 'password');
return response()->json( $credentials );
try {
// attempt to verify the credentials and create a token for the user
if (! $token = JWTAuth::attempt($credentials)) {
return response()->json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) {
// something went wrong whilst attempting to encode the token
return response()->json(['error' => 'could_not_create_token'], 500);
}
// all good so return the token
return response()->json(compact('token'));
}
}
Route in Web.php
Route::post('/authenticate', 'Auth\LoginController@authenticate');
In my login.vue file:
login(){
axios.post('/authenticate',{
email: this.email,
password: this.password
})
.then(response => {
console.log(response);
})
.catch(error => {
});
}
If I try to login I get this error:
419 (unknown status)
{message: "", exception: "Symfony\Component\HttpKernel\Exception\HttpException",鈥
exception
:
"Symfony\Component\HttpKernel\Exception\HttpException"
file
:
"/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php"
line
:
203
I am new to Token Auth so not sure whats going on. The error seems pretty vague
For anyone facing this I had to put the route in API like
Route::post('/authenticate', 'Auth\LoginController@authenticate');
then post to
/api/authenticate
need csrf_tokens .
Most helpful comment
need csrf_tokens .