-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
💻 Use subdomains to navigate through languages #5829
base: main
Are you sure you want to change the base?
Conversation
I'm figuring out how to share sessions between the different subdomains. |
Figured it out 😄 |
@boryanagoncharenko This is done 😄 maybe you could take a look at this and check that it doesn't break anything! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are 3 things, which seem off when I am testing locally with hedy.local set in the hosts file and as an env variable:
- When I am at a subdomain, e.g. ar.hedy.local, and I login with an account that has a preferred language set to Bulgarian, the language of the profile gets changed to Arabic.
- If I am still at ar.hedy.local, I am logged in and I try to change the language of the user profile (say, to Spanish), the language seems to be correctly selected in the drop-down, the page correctly reloads, but the subdomain is not changed so whole website still shows the content in the subdomain language, i.e. Arabic. If I reload the page, the language I selected is now reset to the subdomain language. So, effectively I have no means to change my profile language if I am within a specific subdomain.
- When I log out, it seems that I only log out for the current subdomain. So if I have a session in the es.hedy.local, then I switch to en.hedy.local and log out, I might be under the impression that I have logged out, but navigating to the es.hedy.local shows me I am have not logged out. This might be a particular issue for environments in which users share computers:
https://github.com/user-attachments/assets/962dc72e-32d4-4a7f-89fb-58e3e6453112
Ah, and one more thing, not so important. When I have the DOMAIN_NAME set to hedy.local, navigating to localhost fails because the langauge is present but its valid is "". We could change def before_route(endpoint, values):
to check for that specific value and in this way we would support that too. Definitely not that important, though.
website/for_teachers.py
Outdated
@@ -653,14 +666,16 @@ def preview_teacher_mode(self): | |||
return redirect("/for-teachers") | |||
|
|||
@route("/exit-preview-teacher-mode", methods=["GET"]) | |||
@route("/exit-preview-teacher-mode", methods=["GET"], subdomain="<subdomaon>") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a typo: "<subdomaon>"
should be "<language>"
? Also, shouldn't there be a language="en"
parameter to the exit_teacher_mode method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Thank you so much
Thank you for your review, Boryana!
Yes you're right, thanks for pointing it out. It should be fixed by now.
You're right 😢 handling the session across the different subdomains is tricky, I managed to maintain the user logged in across sessions but didn't take into account logging out. See how when changing subdomains a new session is created its all very weird
will think about this! |
Change the |
@boryanagoncharenko Thank you for your input, I fixed the problem with the lougout in different subdomains 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the explanation and the changes.
Now, if I am in a specific language (en.hedy.local) and I log in with a user that has a different language preference (bg.hedy.local), I get redirected to the language of the user (bg.hedy.local). Also, when I change the language of the user and the page reloads, I land on the right domain (changing en to es redirects me to es.hedy.local).
However, I am still having an issue with the logout. Here are my steps:
- clear cookies, sessions, local storage, all of that
- go to bg.hedy.local and login with a user that uses bg as a language
- open en.hedy.local (directly changed in the webbrowser)
- open es.hedy.local (again, by changing the URL directly in the browser)
- logout
- click the browser's back button to go to en.hedy.local. At this point, I look as if I am logged in, but if I try to navigate to my-profile, I will be logged out.
- click the back button again (twice) to go to bg.hedy.local. Unfortunately, there I am logged in and I can access the account.
Here is a video:
https://github.com/user-attachments/assets/e559c935-d2c1-4444-94cf-ec8d2b8c5620
Yes, you're right, for some reason in the browser I was trying, things did work, but not in Firefox or Chrome. Can you try again? I think I fixed it. There's a problem though, apparently one can't set or unset the main domain cookie from a subdomain, thus, if I log out from en.hedy.local I'm still logged in in hedy.local, do you have any ideas on how we can do that? I think perhaps some sort of redirection would work, although that's ugly! |
Makes it possible to set the language through subdomains. In order to do this the following changes were made:
subdomain
argument, otherwise pages wouldn't be accesible without being prefixed with the subdomain.Fixes #5720
How to test
In order to test this locally, we need to set an env variable that has a dot in it. The one I used was
hedy.local
, this name should be added to the hosts file in your system prefixed with the languages you want to test, for exampleAfter doing this, before starting the server, you need to set the
DOMAIN_NAME
env variableexport DOMAIN_NAME=hedy.local
After doing this you are set up to test the feature. You can navigate to nl.hedy.local:8080 and see that the language changes, and change it through the language selector. Also log in as a user, and change the preferred language there