visualight's avatar

Admin Panel : Login as user

Hello,

I have a admin panel with a list of users. When i click on the username of a user, i need to open his own page (with his information).

Actually, i loggin as user and i can perform necessary operations but everytime i loggin as a user i am disconnected from my admin panel.

Actually i use the part of code to log me in as user. Do you know a other solution to keep my admin panel active and open Users pages as the user see it ?

Thank You

public function connectAsUser($id)
{
        if (Auth::loginUsingId($id))
        {
            return redirect()->intended('/home');
        }
        else
        {
            return 'ERROR';
        }
}
0 likes
5 replies
frezno's avatar

i don't know why you want to connect as a user. Not to mentionn that in this case you have to know his password what a no go.

As admin you have access to the database with all data. So why don't you just make a query and fetch all data of the user?

visualight's avatar

@frezno Simply, if a user encounter an error or mistake (or not understand) something, i can place me in the right context to see and help the user to resolve the problem.

I do not store uncrypted password in the database. Actually to log me as a user i use : Auth::loginUsingId($id) ==> Solution provided by Laravel.

But such as i said in my previous post, when i connect me as a user, i am disconnected from the admin panel. So i am searching for a secure solution that keep me logged as admin and in the same time i can access to users page simply by a click on his username in the user management console of my admin panel.

bart's avatar
bart
Best Answer
Level 13

@visualight You could store your (admin) user id in a session when changing to a users scenario and add a button like "Return back to admin panel". When clicking this you can do something like Auth::loginUsingId(Session::get());

Best of luck!

Please or to participate in this conversation.