Custom Domains - Share Data between - Share Session
In my application, the user has a team, and this team can have a custom domain.
I created a middleware that validates if the user has a custom domain. If they do and are accessing the application with a default domain, I would like to redirect them to the custom domain. However, when I do this, I lose the session, and the user is taken back to the login screen.
If I hadn't lost the session, the problem would have been resolved, but as I wasn't able to do this, I chose to continue and display a message on the login screen, advising that the user has a custom domain and therefore must log in again, but when redirect also I can no longer display the message on the login page, I even tried to overwrite the login View and pass some information via URL but it is not possible.
The closest i got:
11 Replies
But when redirected like this, it doesn't work, it appears that the params are lost...
HUEWHEUW....
I forgot to pass "/login" in the redirect, and then it redirected to the login and I lost the params.
But if somebody have any idea how to redirect without losing session, just tell me
Try redirecting with session flash. https://laravel.com/docs/10.x/responses#redirecting-with-flashed-session-data
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
I tried this, but it doesn't work, when redirected to the new domain, the session doesn't exist...
Doing with url params it works, but it doesn't seem like the best solution
Right, that makes sense. The sessions are tied to the domain because they are stored in the cookies and cookies are restricted to domains for security reasons. What if you used a different session driver.?
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
The database driver is tied to the ip
hmmm, awesome !!!
i'm going to take a look, return in minutes
I configured it, table is populating, but still losing session...
do i have to configure something on my session file -> domain ?
Honestly I’m not sure. Session flash should still work even without a logged in user. Maybe there’s an addition redirect happening somewhere that’s loosing the session flash.