Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Faking logins with Laravel Auth [closed]

On our service there's admins and other users. I'm using the basic Laravel Auth package for handling registrations, logins etc.

What would be the best way to implement a feature, where an admin user could "fake login" as a regular user, without knowing the actual user's password?

like image 631
Apeli Avatar asked Dec 08 '22 18:12

Apeli


2 Answers

This should work:

Auth::loginUsingId($userId, true);
like image 134
DevK Avatar answered Dec 10 '22 22:12

DevK


There is a function in laravel Auth::loginUsingId():

if(Auth::loginUsingId($userId))
{
    return redirect('/dashboard');
}

by which user can login by using its id in user table only. In this there is no need to pass email, password etc

like image 21
Mayank Pandeyz Avatar answered Dec 10 '22 23:12

Mayank Pandeyz