Skip to content

nagsamayam/admin-fortify

Repository files navigation

Backend authentication for admin

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads


This repo can be used as admin Fortify.

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

Installation

You can install the package via composer:

Add below to your composer.json repositories array

{
    "type": "vcs",
    "url": "https://github.com/nagsamayam/admin-fortify"
}
composer require nagsamayam/admin-fortify

The package will automatically register itself.

You can publish and run the migrations with:

php artisan vendor:publish --provider="NagSamayam\AdminFortify\AdminFortifyServiceProvider" --tag="admin-fortify-migrations"
php artisan migrate

You can publish the DB seeder file with:

php artisan vendor:publish --provider="NagSamayam\AdminFortify\AdminFortifyServiceProvider" --tag="admin-fortify-seeders"

You can publish the config file with:

php artisan vendor:publish --provider="NagSamayam\AdminFortify\AdminFortifyServiceProvider" --tag="admin-fortify-config"

Usage

Add below to your config/auth.php guards array

    'admin' => [
        'driver' => 'session',
        'provider' => 'admins',
    ],

Add below to your config/auth.php providers array

    'admins' => [
        'driver' => 'eloquent',
        'model' => NagSamayam\AdminFortify\Models\Admin::class,
    ],

Create new file in app/Providers/AdminFortifyServiceProvider.php and add below content. Make sure view files exists

    <?php

    namespace App\Providers;

    use Illuminate\Http\Request;
    use NagSamayam\AdminFortify\Fortify;
    use Illuminate\Support\ServiceProvider;
    use Illuminate\Cache\RateLimiting\Limit;
    use Illuminate\Support\Facades\RateLimiter;

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

        /**
        * Bootstrap any application services.
        *
        * @return void
        */
        public function boot()
        {

            RateLimiter::for('admin-login', function (Request $request) {
                return Limit::perMinute(3)->by($request->email . $request->ip())->response(function () {
                    return back()->withErrors(['email' => 'Too many login attempts.',]);
                });
            });

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

            Fortify::loginView(fn () => view('admin.auth.login'));

            Fortify::twoFactorChallengeView(function () {
                return view('admin.auth.two-factor-challenge');
            });
        }
    }
php artisan migrate
php artisan db:seed --class=SuperAdminSeeder

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.