File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -274,14 +274,24 @@ private function configureUserScopeFromModel($authUser): void
274274
275275 // If the user is a Laravel Eloquent model we try to extract some common fields from it
276276 if ($ authUser instanceof Model) {
277- $ username = $ authUser ->getAttribute ('username ' );
277+ $ email = null ;
278+
279+ if ($ authUser ->hasAttribute ('email ' )) {
280+ $ email = $ authUser ->getAttribute ('email ' );
281+ } elseif ($ authUser ->hasAttribute ('mail ' )) {
282+ $ email = $ authUser ->getAttribute ('mail ' );
283+ }
284+
285+ $ username = $ authUser ->hasAttribute ('username ' )
286+ ? (string )$ authUser ->getAttribute ('username ' )
287+ : null ;
278288
279289 $ userData = [
280290 'id ' => $ authUser instanceof Authenticatable
281291 ? $ authUser ->getAuthIdentifier ()
282292 : $ authUser ->getKey (),
283- 'email ' => $ authUser -> getAttribute ( ' email ' ) ?? $ authUser -> getAttribute ( ' mail ' ) ,
284- 'username ' => $ username === null ? $ username : ( string ) $ username ,
293+ 'email ' => $ email ,
294+ 'username ' => $ username ,
285295 ];
286296 }
287297
Original file line number Diff line number Diff line change @@ -15,11 +15,13 @@ class AuthEventsTest extends TestCase
1515
1616 public function testAuthenticatedEventFillsUserOnScope (): void
1717 {
18- $ user = new AuthEventsTestUserModel () ;
18+ $ user = new AuthEventsTestUserModel ;
1919
20- $ user ->id = 123 ;
21- $ user ->username = 'username ' ;
22- $ user->
email =
'[email protected] ' ;
20+ $ user ->forceFill ([
21+ 'id ' => 123 ,
22+ 'username ' => 'username ' ,
23+ 24+ ]);
2325
2426 $ scope = $ this ->getCurrentSentryScope ();
2527
You can’t perform that action at this time.
0 commit comments