lcloss/simple-auth

Auth screens for new Laravel project

Installs: 11

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Language:CSS

Type:package

0.0.9 2023-10-07 15:30 UTC

This package is auto-updated.

Last update: 2024-11-07 17:47:54 UTC


README

SimpleAuth is a package to have a quick authorizations screen in conjunction with Laravel Fortify. It is designed with Laravel 10, but may work with other versions. With this package, you can Login, Register, Recover password and handle Email verification.

Installation

  1. Install the package via composer:

    composer require lcloss/simple-auth
  2. Publish the config file:

    php artisan vendor:publish --provider="Lcloss\SimpleAuth\SimpleAuthServiceProvider"
  3. Publish the Fortify file:

    php artisan vendor:publish --provider="Laravel\Fortify\FortifyServiceProvider"
  4. Regiter login and register views in the Fortify config file:

    // app\Providers\FortifyServiceProvider.php
    public function boot(): void
    {
        /* Login */
        Fortify::loginView(function () {
            return view( config('simple-auth.views.login') );
        });
    
        /* Register */
        Fortify::registerView(function () {
            return view(config('simple-auth.views.register'));
        });
    
        // Forgot Password view
        Fortify::requestPasswordResetLinkView(function () {
            return view(config('simple-auth.views.forgot-password'));
        });
    
        // Reset password view
        Fortify::resetPasswordView(function ($request) {
            return view(config('simple-auth.views.reset-password'), ['request' => $request]);
        });
    
        // Verify email view
        Fortify::verifyEmailView(function () {
            return view(config('simple-auth.views.verify-email'));
        });
    
        // Confirm password view
        Fortify::confirmPasswordView(function () {
            return view(config('simple-auth.views.confirm-password'));
        });
  5. Create a user name from first and last names:

Note that this version of registration screen came with First name and Last name. User's table has a name field, so you can use it to store the full name.

Change the CreateNewUser action to create the name from first and last names:

    // app/Actions/Fortify/CreateNewUser.php
        Validator::make($input, [
            'first_name' => ['required', 'string', 'max:255'],
            'last_name' => ['nullable', 'string', 'max:255'],
            'email' => [
                'required',
                'string',
                'email',
                'max:255',
                Rule::unique(User::class),
            ],
            'password' => $this->passwordRules(),
            'password_confirmation' => ['required', 'same:password'],
        ])->validate();
        
        $name = trim($input['first_name'] . ' ' . $input['last_name']);
  1. Check the FortifyServiceProvider at config/app.php:

    // config/app.php
    'providers' => [
        // ...
        App\Providers\FortifyServiceProvider::class,
    ],
  2. Do the migrations with seed:

    php artisan migrate --seed
  3. Do the npm install and npm run dev commands.

  4. Open your project in the browser and go to /login or /register to see the new views.

Tip: First registration will be the super user.

Configuration

You can change this package's configuration by editing the config/simple-auth.php file.

TODOs

  • Add tests
  • Add translations