| Conditions | 3 | 
| Paths | 4 | 
| Total Lines | 18 | 
| Code Lines | 8 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Tests | 0 | 
| CRAP Score | 12 | 
| Changes | 0 | ||
| 1 | <?php  | 
            ||
| 12 | public function authenticate(Request $request)  | 
            ||
| 13 |     { | 
            ||
| 14 | // grab credentials from the request  | 
            ||
| 15 |         $credentials = $request->only('username', 'password'); | 
            ||
| 16 | |||
| 17 |         try { | 
            ||
| 18 | // attempt to verify the credentials and create a token for the user  | 
            ||
| 19 |             if (!$token = JWTAuth::attempt($credentials)) { | 
            ||
| 20 | return response()->json(['error' => 'invalid_credentials'], 401);  | 
            ||
| 21 | }  | 
            ||
| 22 |         } catch (JWTException $e) { | 
            ||
| 23 | // something went wrong whilst attempting to encode the token  | 
            ||
| 24 | return response()->json(['error' => 'could_not_create_token'], 500);  | 
            ||
| 25 | }  | 
            ||
| 26 | |||
| 27 | // all good so return the token  | 
            ||
| 28 |         return response()->json(compact('token')); | 
            ||
| 29 | }  | 
            ||
| 30 | }  | 
            ||
| 31 |