Skip to content
This repository has been archived by the owner on Apr 2, 2023. It is now read-only.

Commit

Permalink
refactor: using auth() helper instead of read through database in the…
Browse files Browse the repository at this point in the history
… middleware
  • Loading branch information
akunbeben committed May 17, 2021
1 parent 9bb332f commit 2df80de
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/FortifyRoleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ public function register()
'role',
CheckRoles::class
);

$this->app->singleton(
\Laravel\Fortify\Contracts\LoginResponse::class,
\App\Http\Responses\LoginResponse::class
);
}

/**
Expand All @@ -51,6 +46,7 @@ protected function configurePublishing()
__DIR__.'/Http/Middleware/RedirectIfAuthenticated.php' => app_path('Http/Middleware/RedirectIfAuthenticated.php'),
__DIR__.'/Http/Responses/LoginResponse.php' => app_path('Http/Responses/LoginResponse.php'),
__DIR__.'/Models/Role.php' => app_path('Models/Role.php'),
__DIR__.'/Providers/FortifyServiceProvider.php' => app_path('Providers/FortifyServiceProvider.php'),
], 'fortify-role-support');

$this->publishes([
Expand Down
57 changes: 57 additions & 0 deletions src/Providers/FortifyServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace App\Providers;

use App\Actions\Fortify\CreateNewUser;
use App\Actions\Fortify\ResetUserPassword;
use App\Actions\Fortify\UpdateUserPassword;
use App\Actions\Fortify\UpdateUserProfileInformation;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Laravel\Fortify\Fortify;

class FortifyServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}

/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Fortify::createUsersUsing(CreateNewUser::class);
Fortify::updateUserProfileInformationUsing(UpdateUserProfileInformation::class);
Fortify::updateUserPasswordsUsing(UpdateUserPassword::class);
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);

Fortify::loginView(fn () => view('auth.login'));
Fortify::registerView(fn () => view('auth.register'));
Fortify::requestPasswordResetLinkView(fn () => view('auth.passwords.email'));
Fortify::resetPasswordView(fn () => view('auth.passwords.reset'));

RateLimiter::for('login', function (Request $request) {
return Limit::perMinute(5)->by($request->email.$request->ip());
});

RateLimiter::for('two-factor', function (Request $request) {
return Limit::perMinute(5)->by($request->session()->get('login.id'));
});

$this->app->singleton(
\Laravel\Fortify\Contracts\LoginResponse::class,
\App\Http\Responses\LoginResponse::class
);
}
}

0 comments on commit 2df80de

Please sign in to comment.