File tree Expand file tree Collapse file tree 9 files changed +395
-377
lines changed
Expand file tree Collapse file tree 9 files changed +395
-377
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ Make sure you have installed **Node** and [**Yarn**](https://yarnpkg.com/) (late
4444 * `touch database/database.sqlite` to create an empty database file
4545 * `cp .env.example .env` to configure installation
4646 * `php artisan key:generate` to generate unique key for the project
47+ * `php artisan jwt:secret` to generate unique key for the project
4748 * `php artisan migrate` to create all the tables
4849 * `php artisan db:seed` to fill the tables with fake data
4950 * `php artisan serve` to serve application on localhost:8000
Original file line number Diff line number Diff line change @@ -33,3 +33,5 @@ MAIL_ENCRYPTION=null
3333PUSHER_APP_ID =
3434PUSHER_KEY =
3535PUSHER_SECRET =
36+
37+ JWT_SECRET =
Original file line number Diff line number Diff line change 44
55use Illuminate \Http \Request ;
66use Auth ;
7- use JWTAuth ;
87use JWTException ;
98
109class LoginController extends Controller
@@ -16,15 +15,15 @@ public function login(Request $request)
1615
1716 try {
1817 // attempt to verify the credentials and create a token for the user
19- if (! $ token = JWTAuth:: attempt ($ credentials )) {
18+ if (!$ token = Auth:: guard ( ' api ' )-> attempt ($ credentials )) {
2019 return response ()->json (['messages ' => ['E-mail ou senha não conferem ' ]], 401 );
2120 }
2221 } catch (JWTException $ e ) {
2322 // something went wrong whilst attempting to encode the token
2423 return response ()->json (['messages ' => ['Não foi possível gerar o token ' ]], 500 );
2524 }
2625
27- $ user = Auth::user ();
26+ $ user = Auth::guard ( ' api ' )-> user ();
2827
2928 // all good so return the token
3029 return response ()->json (compact ('token ' , 'user ' ));
Original file line number Diff line number Diff line change 44
55use Illuminate \Notifications \Notifiable ;
66use Illuminate \Foundation \Auth \User as Authenticatable ;
7+ use Tymon \JWTAuth \Contracts \JWTSubject ;
78
8- class User extends Authenticatable
9+ class User extends Authenticatable implements JWTSubject
910{
1011 use Notifiable;
1112
@@ -26,4 +27,14 @@ class User extends Authenticatable
2627 protected $ hidden = [
2728 'password ' , 'remember_token ' ,
2829 ];
30+
31+ public function getJWTIdentifier ()
32+ {
33+ return $ this ->id ;
34+ }
35+
36+ public function getJWTCustomClaims ()
37+ {
38+ return [];
39+ }
2940}
Original file line number Diff line number Diff line change 44 "keywords" : [" framework" , " laravel" ],
55 "license" : " MIT" ,
66 "type" : " project" ,
7+ "minimum-stability" : " dev" ,
8+ "prefer-stable" : true ,
79 "require" : {
810 "php" : " >=5.6.4" ,
911 "laravel/framework" : " 5.3.*" ,
1012 "barryvdh/laravel-cors" : " ^0.8.2" ,
11- "tymon/jwt-auth" : " 0.5.* " ,
13+ "tymon/jwt-auth" : " ~1.0 " ,
1214 "predis/predis" : " ^1.1"
1315 },
1416 "require-dev" : {
You can’t perform that action at this time.
0 commit comments