Jwt-auth: Post 419 (unknown status) error

Created on 14 Sep 2017  路  2Comments  路  Source: tymondesigns/jwt-auth

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

Most helpful comment

need csrf_tokens .

All 2 comments

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 .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lloy0076 picture lloy0076  路  3Comments

agneshoving picture agneshoving  路  3Comments

kofi1995 picture kofi1995  路  3Comments

therealmjk picture therealmjk  路  3Comments

phamduong picture phamduong  路  3Comments