You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cannot get the current login user in the login event listener when I re-login, it returns null when using the Auth::user()
Steps To Reproduce:
Create login event listener and write the Log::info("Current user:", ['user' => Auth::user()]); in the handle method
The Authentication Guards driver is session
Login the web
Call Auth::logout() to log out of the currently logged-in user
Call Auth::loginUsingId($another_user_id) to log in to the specified user
Result
In the log file we got the message local.INFO: Current user: {"user":null}, we cannot get the current login user
Excepted
local.INFO: Current user: {"user": {"name": "another user"}}
Reason
The loggedOut property is set to true once the Auth::logout() method has been called, it will be set to false when we re-login the user, but the login event has been fired before the loggedOut property is updated.
Suggestion
When we call the login() method, we could always set the loggedOut property to true.
I am not the native english speaker, sorry for my bad english.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description:
Cannot get the current login user in the login event listener when I re-login, it returns null when using the
Auth::user()
Steps To Reproduce:
Log::info("Current user:", ['user' => Auth::user()]);
in the handle methodAuth::logout()
to log out of the currently logged-in userAuth::loginUsingId($another_user_id)
to log in to the specified userResult
In the log file we got the message
local.INFO: Current user: {"user":null}
, we cannot get the current login userExcepted
local.INFO: Current user: {"user": {"name": "another user"}}
Reason
The loggedOut property is set to true once the Auth::logout() method has been called, it will be set to false when we re-login the user, but the login event has been fired before the loggedOut property is updated.
Suggestion
When we call the
login()
method, we could always set the loggedOut property to true.I am not the native english speaker, sorry for my bad english.
Beta Was this translation helpful? Give feedback.
All reactions