Petro Gromovo
Petro Gromovo

Reputation: 2171

Why file app/Providers/JetstreamServiceProvider.php on Jetstream 5 site is different I read in docs and how to work with it?

On Laravel / Livewire / Jetstream site I try to change name of field by which user login into the site and I changed in config/fortify.php:

'username' => 'login', // 'email',

and checking docs for 5 branch at https://jetstream.laravel.com/features/authentication.html#customizing-user-authentication I read :

The authenticateUsing method accepts a closure that receives the incoming HTTP request. The closure is responsible for validating the login credentials attached to the request and returning the associated user instance. If the credentials are invalid or no user can be found, null or false should be returned by the closure. Typically, this method should be called from the boot method of your JetstreamServiceProvider:

<?php

use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Laravel\Fortify\Fortify;

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

    Fortify::authenticateUsing(function (Request $request) {
        $user = User::where('email', $request->email)->first();

        if ($user &&
            Hash::check($request->password, $user->password)) {
            return $user;
        }
    });
}

But opening file app/Providers/JetstreamServiceProvider.php it has different content :

<?php

namespace App\Providers;

use App\Actions\Jetstream\DeleteUser;
use Illuminate\Support\ServiceProvider;
use Laravel\Jetstream\Jetstream;

class JetstreamServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        $this->configurePermissions();

        Jetstream::deleteUsersUsing(DeleteUser::class);
    }

    /**
     * Configure the permissions that are available within the application.
     */
    protected function configurePermissions(): void
    {
        Jetstream::defaultApiTokenPermissions(['read']);

        Jetstream::permissions([
            'create',
            'read',
            'update',
            'delete',
        ]);
    }
}

Searching in my project I did not find any substring like Fortify::authenticateUsing.

In which way I have to edit this file to change name of field by which user login into the site ?

"laravel/framework": "^11.31",
"laravel/jetstream": "^5.3",
"livewire/livewire": "^3.0",

Upvotes: 0

Views: 14

Answers (0)

Related Questions