Closed nelero closed 8 months ago
@nelero thanks for your first bug report. Mind providing a PR to fix this issue?
Hi i got the same problem, did you find a solution??
@nelero Latest version was latest "stable" version, or dev-master? @nelero @maurixxxx we added some fixes to the master, do you mind testing your issue, if everything works fine now or report any (new) issue occuring?
I'll try it
I did the upgrade to the 4.1.0 version but it doesn't fix the issue. After login customer is redirect to the main domain.
and if i disable the module everything goes right.
In my opinion the problem is the AfterLoginPlugin, a part of code is:
$targetUrl = $this->session->getAfterLoginReferer();
if (empty($targetUrl)) {
$targetUrl = $this->defaultTargetUrl;
}
If Redirect Customer to Account Dashboard after Logging in
is NO then targetUrl allway is empty. For that defaultTargetUrl is used as final url. As you can see in di.xml file defaultTargetUrl is / instead of /spesific/.
<type name="BitExpert\ForceCustomerLogin\Plugin\AfterLoginPlugin">
<arguments>
<argument name="defaultTargetUrl" xsi:type="string">/</argument>
</arguments>
</type>
Maybe there is an explanation about this behaviour but it doesn't have for me.
I've write a custom module that have a plugin of bitExpert's AfterLoginPlugin. This plugin dynamically decide which is the final url:
public function afterAfterExecute(\BitExpert\ForceCustomerLogin\Plugin\AfterLoginPlugin $overrided, $resultRedirect)
{
$targetUrl = $this->session->getAfterLoginReferer();
if (empty($targetUrl) && $this->session->isSessionExists()) {
$resultRedirect->setUrl($url);
}
return $resultRedirect;
}
private function getBaseUrl()
{
$secure = $this->getForceSecureRedirectOption();
$secure = ($secure === true) ? true : null;
return $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB, $secure);
}
private function getForceSecureRedirectOption()
{
return (bool) $this->scopeConfig->getValue(
LoginCheckInterface::MODULE_CONFIG_FORCE_SECURE_REDIRECT,
ScopeInterface::SCOPE_STORE
);
}
Anyway bitExpert team, thanks for the great plug in.
@rikwillems if you are up for another task, this one has been open for way too long now :)
@nelero working with subdirectories can be a great pain. I think your base url is not properly resolved since that is used in the Magento redirect.
Since some time I have used an additional php file to determine store code and that works very good. With that solution I cannot reproduce the issue you describe as the base url is properly resolved.
Append your composer.json
with an additional autoload file
"autoload": {
"files": [
"app/etc/NonComposerComponentRegistration.php",
"app/etc/stores.php"
],
},
Do some magic to determine store code in app/etc/stores.php
<?php
use \Magento\Store\Model\StoreManager;
if (!isset($_SERVER['REQUEST_URI'])) {
return;
}
$hostName = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
$uriParts = explode('/', trim($_SERVER['REQUEST_URI'], '/'));
$code = '';
$runCode = 'default';
$runType = 'store';
$subdirectories = [
'subdir',
];
$domainRegexes = [
'(?P<code>(second|third)).ce24.test',
];
foreach ($domainRegexes as $regex) {
if (preg_match('/'.$regex.'$/i', $hostName, $matches)) {
$code = $matches['code'];
break;
}
}
$runCodeMapping = [
'second' => 'second',
'third' => 'third',
];
$runCode = $runCodeMapping[$code] ?? $runCode;
if (in_array($uriParts[0], $subdirectories)) {
$_SERVER['REQUEST_URI'] = preg_replace('/\/' . $uriParts[0] . '/', '', $_SERVER['REQUEST_URI'], 1);
$runCode = $uriParts[0];
}
$_SERVER[StoreManager::PARAM_RUN_TYPE] = $runType;
$_SERVER[StoreManager::PARAM_RUN_CODE] = $runCode;
Thanks for your reply. I'm not concerned with this issue anymore, as we moved to subdomains since 3 years now.
Regards,
Le mer. 3 janv. 2024 à 13:57, Rik Willems @.***> a écrit :
@nelero https://github.com/nelero working with subdirectories can be a great pain. I think your base url is not properly resolved since that is used in the Magento redirect.
Since some time I have used an additional php file to determine store code and that works very good. With that solution I cannot reproduce the issue you describe as the base url is properly resolved.
Append your composer.json with an additional autoload file
"autoload": { "files": [ "app/etc/NonComposerComponentRegistration.php", "app/etc/stores.php" ], },
Do some magic to determine store code in app/etc/stores.php
<?php
use \Magento\Store\Model\StoreManager;
if (!isset($_SERVER['REQUEST_URI'])) { return; }
$hostName = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; $uriParts = explode('/', trim($_SERVER['REQUEST_URI'], '/')); $code = ''; $runCode = 'default'; $runType = 'store';
$subdirectories = [ 'subdir', ];
$domainRegexes = [ '(?P
(second|third)).ce24.test', ];
foreach ($domainRegexes as $regex) { if (preg_match('/'.$regex.'$/i', $hostName, $matches)) { $code = $matches['code']; break; } }
$runCodeMapping = [ 'second' => 'second', 'third' => 'third', ];
$runCode = $runCodeMapping[$code] ?? $runCode;
if (in_array($uriParts[0], $subdirectories)) { $_SERVER['REQUEST_URI'] = preg_replace('/\/' . $uriParts[0] . '/', '', $_SERVER['REQUEST_URI'], 1); $runCode = $uriParts[0]; }
$_SERVER[StoreManager::PARAM_RUN_TYPE] = $runType; $_SERVER[StoreManager::PARAM_RUN_CODE] = $runCode;
— Reply to this email directly, view it on GitHub https://github.com/bitExpert/magento2-force-login/issues/181#issuecomment-1875332407, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEQ6MW32OSI4QPILKMC5ITYMVISRAVCNFSM4LRLYZE2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBXGUZTGMRUGA3Q . You are receiving this because you were mentioned.Message ID: @.***>
@shochdoerfer I am closing this issue.
@rikwillems thx for posting your explanation here. Maybe someone will find it in the future :)
Hi, if you have multistore configuration, with a website configurated in subfolder, multiples problems occured :
if error occured on login, the visitor is redirected to root level (website) and not the website he was trying to log in.
Configuration default website : https://mywebsite.com/ Force login not enabled
Configuration first website : https://mywebsite.com/ force login not enabled
Configuration second website : https://anothersite.com/**specific/ force login ENABLED**
configuration third website : https://anothersite.com/ force login not enabled
trying to access homepage for https://anothersite.com/**specific**/ redirect to https://anothersite.com/specific/customer/account/login even with default entries.
Making error in logging in to https://anothersite.com/specific/customer/account/login redirects visitor to https://anothersite.com/ instead of https://anothersite.com/**specific**/
Preconditions
Magento Version : 2.3.4
Force Login Module Version : Latest
Even if we add entries for this specific store, we had to precise everytime the subfolder.