Skip to content

Commit

Permalink
Setting user id only if the user exist despite alive session (#428)
Browse files Browse the repository at this point in the history
Co-authored-by: Artem Zherdev <[email protected]>
  • Loading branch information
zherdev-artem and artemzherdev authored Nov 14, 2021
1 parent 8c9aa7d commit cbe1f8b
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/Aimeos/Shop/Base/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,9 @@ protected function addUser( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeo
$key = collect( config( 'shop.routes' ) )->where( 'prefix', optional( Route::getCurrentRoute() )->getPrefix() )->keys()->first();
$guard = data_get( config( 'shop.guards' ), $key, Auth::getDefaultDriver() );

if( ( $userid = Auth::guard( $guard )->id() ) !== null ) {
$context->setUserId( $userid );
}

if( ( $user = Auth::guard( $guard )->user() ) !== null ) {
$context->setEditor( $user->name );
$context->setUserId( $user->id );
} elseif( $ip = \Request::ip() ) {
$context->setEditor( $ip );
}
Expand Down

1 comment on commit cbe1f8b

@aimeos
Copy link
Owner

@aimeos aimeos commented on cbe1f8b Nov 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@artemzherdev Can you please check the following?

Auth::guard()->user() returns an Authenticable contract which doesn't necessary have id and name properties:
https://github.com/laravel/framework/blob/8.x/src/Illuminate/Contracts/Auth/Guard.php#L21-L26
https://github.com/laravel/framework/blob/8.x/src/Illuminate/Contracts/Auth/Authenticatable.php

Does this work too or even better when used with other authentication methods?

$context->setEditor( $user->getAuthIdentifierName() );
$context->setUserId( $user->getAuthIdentifier() );

Please sign in to comment.