kapitan
kapitan

Reputation: 2222

Do Console.Log Laravel If Authentication Is Successfull

I need to make a console.log(user_id + ' signed-in successfully'); on user's successful login.

My problem is where and how would I place the trigger?

This is the only thing that I can see on my Http\Controllers\Auth\LoginController:

    use Illuminate\Foundation\Auth\AuthenticatesUsers;

    protected $redirectTo = '/master.php';

    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    public function showLogin()
    {
        return view('page.login_form');
    }

Any advised?

UPDATE:

My actual purpose is that I want to notify the other signed-in users that a new user has just signed-in using socket.io. This part is I know how to do.

I also know how to do toastr notification from a controller. say when a user saved a certain record. Which is triggering a javascript from a controller - same thing what I want to accomplish during the user login.

That's why if I can only do the console.log() on the login, I can do it from there.

Upvotes: 0

Views: 307

Answers (2)

kapitan
kapitan

Reputation: 2222

I have solved the problem by using the authenticated method inside the LoginController.

protected function authenticated(Request $request, $user)
{
  // Session::flash(); --> PUT MY CODE HERE TO FIRE THE console.log();

  return redirect()->route('');
}

Upvotes: 1

Nabil Farhan
Nabil Farhan

Reputation: 1536

You can create a /landing page whose sole purpose will be to notify other user and then redirect again to /master.php.

You need to change to protected $redirectTo = '/landing';. You should also insert a middleware to make sure without logging in a user won't be able to go to /landing.

At /landing page you will fire the notification and then redirect to /master.php. From there you will continue normal operations.

Upvotes: 0

Related Questions