Skip to content

Commit

Permalink
zwracanie info o zalogowanym userze
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-boduch committed May 16, 2019
1 parent dc66186 commit 7197514
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 33 deletions.
18 changes: 18 additions & 0 deletions app/Http/Controllers/Api/UserController.php
@@ -0,0 +1,18 @@
<?php

namespace Coyote\Http\Controllers\Api;

use Illuminate\Routing\Controller;
use Illuminate\Contracts\Auth\Factory as Auth;

class UserController extends Controller
{
/**
* @param Auth $auth
* @return mixed
*/
public function index(Auth $auth)
{
return $auth->guard('api')->user();
}
}
38 changes: 7 additions & 31 deletions app/Http/Middleware/Authenticate.php
Expand Up @@ -2,42 +2,18 @@

namespace Coyote\Http\Middleware;

use Closure;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\Request;
use Illuminate\Auth\Middleware\Authenticate as BaseAuthenticate;

class Authenticate extends AbstractMiddleware
class Authenticate extends BaseAuthenticate
{
/**
* The Guard implementation.
* Get the path the user should be redirected to when they are not authenticated.
*
* @var Guard
* @param \Illuminate\Http\Request $request
* @return string
*/
protected $auth;

/**
* Create a new filter instance.
*
* @param Guard $auth
*/
public function __construct(Guard $auth)
protected function redirectTo($request)
{
$this->auth = $auth;
}

/**
* Handle an incoming request.
*
* @param Request $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->guest()) {
return $this->login($request);
}

return $next($request);
return route('login');
}
}
2 changes: 1 addition & 1 deletion app/Models/User.php
Expand Up @@ -101,7 +101,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
*
* @var array
*/
protected $hidden = ['password', 'remember_token', 'email'];
protected $hidden = ['password', 'remember_token', 'email', 'salt', 'provider_id', 'provider', 'guest_id'];

/**
* @var string
Expand Down
3 changes: 2 additions & 1 deletion app/Providers/AuthServiceProvider.php
Expand Up @@ -100,7 +100,8 @@ public function boot()
});
}

Passport::routes();
// Passport::routes();
Passport::personalAccessClientId(1);
}

/**
Expand Down
1 change: 1 addition & 0 deletions routes/api.php
Expand Up @@ -7,5 +7,6 @@
$this->prefix('v1')->group(function () {
$this->get('microblogs', ['uses' => 'Api\Microblog\HomeController@index']);
$this->post('login', ['uses' => 'Api\LoginController@login']);
$this->get('user', ['uses' => 'Api\UserController@index', 'middleware' => 'auth:api']);
});

0 comments on commit 7197514

Please sign in to comment.