Skip to content

Save last login method in a cookie #12286

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

humitos
Copy link
Member

@humitos humitos commented Jul 2, 2025

Initial attempt to save the "last login method" into a cookie so we can show a visual label next to the button to login.

This is only the backend part. We need to write some code in the template to use this value next.

I'm not happy with the implementation because looks pretty complex. I didn't find an easier way to do it and I'm open for suggestions.

Required by readthedocs/ext-theme#421

Initial attempt to save the "last login method" into a cookie so we can show a
visual label next to the button to login.

This is only the backend part. We need to write some code in the template to use
this value next.

I'm not happy with the implementation because looks pretty complex. I didn't
find an easier way to do it and I'm open for suggestions.

Required by readthedocs/ext-theme#421
@agjohnson
Copy link
Contributor

Alternatively, we could use basic events on elements in the login UI to set a cookie from the client side. If the user last clicked on the GitHub button or Email tab, we store that and either consume it at the backend and use it as context data into the view, or it's also possible to do this all on the front end side but it will be a fair amount of JS.

@humitos
Copy link
Member Author

humitos commented Jul 10, 2025

What about subscribing to all the social buttons and email's submit button and use using cookieStore.set() in the frontend to save the cookie? This cookie will be sent to the server and we can read it from the backend to render the template with this value. I think that's probably the best of the two worlds.

@ericholscher
Copy link
Member

Seems like hooking into allauth is probably the right place here? Doing middleware feels really heavy. I looked briefly at the docs and couldn't find an obvious place. @stsewd do you know if there's a good spot to hook here?

@agjohnson
Copy link
Contributor

agjohnson commented Jul 11, 2025

What about subscribing to all the social buttons and email's submit button and use using cookieStore.set() in the frontend to save the cookie? This cookie will be sent to the server and we can read it from the backend to render the template with this value

Is this different than what I suggested? #12286 (comment)

Seems like you're suggesting the same thing, I think that's fine yeah.

@humitos
Copy link
Member Author

humitos commented Jul 14, 2025

Seems like you're suggesting the same thing,

Now that I re-read your comment, it seems I'm suggesting the same, yeah haha 😅

I tried cookieStorage.set() the other day but it fails locally because it's not secure:

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

(from https://developer.mozilla.org/en-US/docs/Web/API/CookieStore/set)

So, I will need to disable that somehow for developing or add SSL somehow to the local environment.

This comment was marked as resolved.

This comment was marked as resolved.

@humitos
Copy link
Member Author

humitos commented Jul 14, 2025

This is now working as I want. We read the cookie set by the front-end and expose 2 variables in the context for the templates:

  • last_login_method: it will be the provider.id set by the front end (github, githubapp, sso, etc)
  • last_login_tab: it will communicate the front-end what's the tab should be activated (vcs, email, sso)

@humitos humitos marked this pull request as ready for review July 14, 2025 12:45
@humitos humitos requested a review from a team as a code owner July 14, 2025 12:45
@humitos humitos requested a review from ericholscher July 14, 2025 12:45
@humitos humitos requested a review from stsewd July 15, 2025 10:27
@stsewd stsewd requested a review from agjohnson July 15, 2025 15:34
Copy link
Member

@stsewd stsewd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be fine with this, but still think just having this on the client side with the local storage makes more sense. @agjohnson probably knows better how much work that would be, we are already using bindings to hide content based on conditions.

@humitos
Copy link
Member Author

humitos commented Jul 15, 2025

@stsewd we already discussed this in #12286 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants