简体   繁体   中英

How do I authenticate a user in Laravel 8 Jetstream only if his status is active?

I am building a Laravel 8 application and have successfully implemented authentication. Now I want to check if a user's status is active before logging him in. I have added a field in the users table

username varchar
password varchar
....
status tinyint(1)
...

I am using JetStream and Fortify

Thank You

I am building a Laravel 8 application and have successfully implemented authentication. Now I want to check if a user's status is active before logging him in. I have added a field in the users table

username varchar
password varchar
....
status tinyint(1)
...

I am using JetStream and Fortify

Thank You

This is with a custom error message.

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

    if ($user && Hash::check($request->password, $user->password)) {
        if ($user->active == 1) {  // it will return if status == 1
            return $user;
        }
        throw ValidationException::withMessages(['Your Message Here!']);        
    }

});

I am building a Laravel 8 application and have successfully implemented authentication. Now I want to check if a user's status is active before logging him in. I have added a field in the users table

username varchar
password varchar
....
status tinyint(1)
...

I am using JetStream and Fortify

Thank You

您也应该添加:使用 Illuminate\\Support\\Facades\\Hash;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM