Created
November 17, 2015 15:25
-
-
Save d30jeff/a8a1690cc60241e4d956 to your computer and use it in GitHub Desktop.
Why Laravel, Whyyy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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