Skip to content

Commit cfd290f

Browse files
imbrishtaylorotwell
authored andcommitted
Set current user before firing authenticated event (#21790)
1 parent 1dffaad commit cfd290f

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/Illuminate/Auth/SessionGuard.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,9 @@ public function user()
127127
// First we will try to load the user using the identifier in the session if
128128
// one exists. Otherwise we will check for a "remember me" cookie in this
129129
// request, and if one exists, attempt to retrieve the user using that.
130-
$user = null;
131-
132130
if (! is_null($id)) {
133-
if ($user = $this->provider->retrieveById($id)) {
134-
$this->fireAuthenticatedEvent($user);
131+
if ($this->user = $this->provider->retrieveById($id)) {
132+
$this->fireAuthenticatedEvent($this->user);
135133
}
136134
}
137135

@@ -140,17 +138,17 @@ public function user()
140138
// the application. Once we have a user we can return it to the caller.
141139
$recaller = $this->recaller();
142140

143-
if (is_null($user) && ! is_null($recaller)) {
144-
$user = $this->userFromRecaller($recaller);
141+
if (is_null($this->user) && ! is_null($recaller)) {
142+
$this->user = $this->userFromRecaller($recaller);
145143

146-
if ($user) {
147-
$this->updateSession($user->getAuthIdentifier());
144+
if ($this->user) {
145+
$this->updateSession($this->user->getAuthIdentifier());
148146

149-
$this->fireLoginEvent($user, true);
147+
$this->fireLoginEvent($this->user, true);
150148
}
151149
}
152150

153-
return $this->user = $user;
151+
return $this->user;
154152
}
155153

156154
/**

0 commit comments

Comments
 (0)