Skip to content

Commit

Permalink
Remove the facade aliases usage since they can be removed/changed fro… (
Browse files Browse the repository at this point in the history
#215)

* Remove the facade aliases usage since they can be removed/changed from the Laravel configuration which will make impossible to install and use the plugin.

* Import the facade using use statements and use the app function to avoid having the full classname.

* Update PHPStan configuration to ignore the Event::listen error since we're not using the alias anymore
  • Loading branch information
Rezouce authored Apr 30, 2021
1 parent 9915335 commit 48b5b0c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ parameters:
checkGenericClassInNonGenericObjectType: false
level: 2
ignoreErrors:
- '#Call to an undefined static method Event::listen#'
- '#Call to static method#'
paths:
- src
18 changes: 10 additions & 8 deletions src/Auth0/Login/LoginServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Auth0\SDK\Store\StoreInterface;
use Illuminate\Auth\RequestGuard;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;

class LoginServiceProvider extends ServiceProvider
Expand All @@ -21,11 +23,11 @@ class LoginServiceProvider extends ServiceProvider
*/
public function boot()
{
\Auth::provider('auth0', function ($app, array $config) {
Auth::provider('auth0', function ($app, array $config) {
return $app->make(Auth0UserProvider::class);
});

\Auth::extend('auth0', function ($app, $name, $config) {
Auth::extend('auth0', function ($app, $name, $config) {
return new RequestGuard(function (Request $request, Auth0UserProvider $provider) {
return $provider->retrieveByCredentials(['api_token' => $request->bearerToken()]);
}, $app['request'], $app['auth']->createUserProvider($config['provider']));
Expand Down Expand Up @@ -73,14 +75,14 @@ public function register()
});

// When Laravel logs out, logout the auth0 SDK trough the service
\Event::listen('auth.logout', function () {
\App::make('auth0')->logout();
Event::listen('auth.logout', function () {
app('auth0')->logout();
});
\Event::listen('user.logout', function () {
\App::make('auth0')->logout();
Event::listen('user.logout', function () {
app('auth0')->logout();
});
\Event::listen('Illuminate\Auth\Events\Logout', function () {
\App::make('auth0')->logout();
Event::listen('Illuminate\Auth\Events\Logout', function () {
app('auth0')->logout();
});
}
}
2 changes: 1 addition & 1 deletion src/Auth0/Login/Repository/Auth0UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getUserByUserInfo(array $userInfo) : Authenticatable
public function getUserByIdentifier($identifier) : ?Authenticatable
{
// Get the user info of the user logged in (probably in session)
$user = \App::make('auth0')->getUser();
$user = app('auth0')->getUser();

if ($user === null) {
return null;
Expand Down

0 comments on commit 48b5b0c

Please sign in to comment.