Skip to content

Instantly share code, notes, and snippets.

@d30jeff
Created November 17, 2015 15:25
Show Gist options
  • Select an option

  • Save d30jeff/a8a1690cc60241e4d956 to your computer and use it in GitHub Desktop.

Select an option

Save d30jeff/a8a1690cc60241e4d956 to your computer and use it in GitHub Desktop.
Why Laravel, Whyyy
class AuthenticateController extends Controller
{
public function index()
{
}
public function authenticate(Request $request)
{
$credentials = $request->only('email', 'password');
/*$credentials = [
'email' => '[email protected]',
'password' => 'admin'
];*/
try {
// 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
return response()->json(['error' => 'could_not_create_token'], 500);
}
// if no errors are encountered we can return a JWT
return response()->json(compact('token'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment