When a user visits a website, their browser stores session information and cookies related to that particular domain. The “www” prefix is considered a subdomain, and cookies set on the main domain (without the “www” prefix) may not be accessible or recognized by the subdomain.
In your case, it’s possible that the session data or authentication cookies required for retrieving the logged-in user are not accessible when accessing the application with the “www” prefix. As a result, the \BackendAuth::getUser() method returns null.
To resolve this issue, you should ensure that your session configuration and cookie settings are consistent across the main domain and its subdomains. Specifically, check the SESSION_DOMAIN setting in your Laravel configuration (config/session.php) and make sure it is set to the appropriate value. For example, you may need to set it to .mywebsite.com (note the leading dot) to allow cookies and session data to be shared across subdomains.
Additionally, double-check your web server configuration to ensure that requests to both the “www” and non-www versions of your domain are correctly handled and routed to the same application instance.
By aligning the session configuration and ensuring consistent cookie accessibility, you should be able to retrieve the logged-in user regardless of whether the “www” prefix is present in the URL.
Hopefully this help! @daft let me know if you have any comments
UPDATE #322 lol
Some users still experience the issue, even after cleaning the cookies on their browser, it’s weird…