How do I customize the context.php in vendor folder?
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
How do I customize the context.php in vendor folder?
In vendor/aimeos/aimeos-core/src/MShop/Context.php, there is a function about retrieving user,
I want it to return auth()->id() instead, is there anyway I can override the file just like the usual manager for models, or is there other ways of configuring the authentication?
Version:
"aimeos/aimeos-laravel": "~2023.10",
"php": "^8.1.0",
Code: Select all
public function user() : ?string
{
if( $this->user instanceof \Closure )
{
$fcn = $this->user;
$this->user = $fcn();
}
return $this->user;
}
Version:
"aimeos/aimeos-laravel": "~2023.10",
"php": "^8.1.0",
Re: How do I customize the context.php in vendor folder?
No, that won't work and will result in errors whenever $context->user() is called because you would return an unexpected value. Instead, use
Code: Select all
$context->user()->getId()
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: How do I customize the context.php in vendor folder?
Thanks for the reply.
I couldn't get the customer get self jsonapi to work (ie. returning everything null when logged in), except changing the user function (in context.php of vendor folder) to return the laravel auth user id instead. I'm using laravel passport for user auth. Hence I'd like to know:
1. If there is any setup I can do to override the context.php file (just like overriding the model manager through custom extension), and
2. If there is anything wrong with laravel passport compatibility with the library.
I couldn't get the customer get self jsonapi to work (ie. returning everything null when logged in), except changing the user function (in context.php of vendor folder) to return the laravel auth user id instead. I'm using laravel passport for user auth. Hence I'd like to know:
1. If there is any setup I can do to override the context.php file (just like overriding the model manager through custom extension), and
2. If there is anything wrong with laravel passport compatibility with the library.
Re: How do I customize the context.php in vendor folder?
From another post I read that the user function works if Auth::id() returns the correct user id.
However, Laravel by default uses guard 'web' instead of 'api'. If I change the default guard to api, the aimeos backend wouldn't login. How do I configure aimeos to use guard 'api' instead? (ie. auth('api')->id() instead of Auth::id())
However, Laravel by default uses guard 'web' instead of 'api'. If I change the default guard to api, the aimeos backend wouldn't login. How do I configure aimeos to use guard 'api' instead? (ie. auth('api')->id() instead of Auth::id())
Re: How do I customize the context.php in vendor folder?
No, and the approach is wrong. Try to find out why the customer item isn't loaded here:
https://github.com/aimeos/aimeos-larave ... t.php#L287
We haven't used Passport for authentication up to now but there should be no principle problem.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: How do I customize the context.php in vendor folder?
Thanks for the reply! Just one more question, may I know if there's any configurations for setting the auth guard? Thanks!!bar_on wrote: ↑07 Nov 2024, 06:47 From another post I read that the user function works if Auth::id() returns the correct user id.
However, Laravel by default uses guard 'web' instead of 'api'. If I change the default guard to api, the aimeos backend wouldn't login. How do I configure aimeos to use guard 'api' instead? (ie. auth('api')->id() instead of Auth::id())
Re: How do I customize the context.php in vendor folder?
You can change the guard in the ./config/shop.php using the "guards" key:
https://github.com/aimeos/aimeos-larave ... t.php#L281
https://github.com/aimeos/aimeos-larave ... t.php#L281
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: How do I customize the context.php in vendor folder?
It works now! Thank you very much.aimeos wrote: ↑12 Nov 2024, 08:36 You can change the guard in the ./config/shop.php using the "guards" key:
https://github.com/aimeos/aimeos-larave ... t.php#L281
For anyone using jsonapi with laravel passport, the setup in shop.php is
'guards' => ['jsonapi' => 'your own guard name'].