mercredi 23 janvier 2019

Vue.js & jwt-auth with Missing Boundary

I can use my login method to authenticate with Postman and Insomnia. However, when I try it with Vuex in a PWA, I receive the message

Warning: Missing boundary in multipart/form-data POST data in Unknown on line 0
{"error":"Unauthorized"}

This is my login method

public function login(Request $request) {
        $credentials = $request->only(['email', 'password']);

        try
           {
               if(!$token = JWTAuth::attempt($credentials)) {
                   return response()->json(['error' => 'Unauthorized'], 401);
               } // end if
           } 
        catch(JWTException $e)
           {
               return response()->json(['error' => 'Could not create token'], 500);
           } // End try...catch

        return $this->respondsWithToken($token);
    } // end function

And this is my Vuex action

export const login = (context, credentials) => {
    axios.post('api/login', {
        username: credentials.username,
        password: credentials.password
    }, {
        headers: {'Content-Type': 'multipart/form-data;'},
    })
        .then(rsp => {
            console.log('LOGIN', rsp);
        })
        .catch(error => {
            console.log(error)
        })
};

When I post credentials to that endpoint in Insomnia, I get the response

{
  "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvYmVhY29uLmRldlwvYXBpXC9sb2dpbiIsImlhdCI6MTU0O123A567NiwiZXhwIjoxNTQ5NDQ4OTg2LCJuYmYiOjE1NDgyMzkzODYsImp0aSI6IjhVNDJHWndVMWtHbWVzSkUiLCJzdWIiOjEsInBydiI6Ijg3ZTBhZjFlZjlmZDE1ODEyZmRlYzk3MTUzYTE0ZTBiMDQ3NTQ2YWEifQ.KeGFiAoddim8p1YNKv5vO09H2ZIKa2RZp8Z1yXWqILk",
  "token_type": "bearer"
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire