Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

RecursionError when trying to access current_user after changing alternative token #836

Closed
mconigliaro opened this issue Feb 28, 2024 · 1 comment

Comments

@mconigliaro
Copy link

I'm actually not sure whether this is a bug or if I'm just misunderstanding something. The docs for Alternative Tokens say:

This way you are free to change the user’s alternative id to a new randomly generated value when the user changes their password, which would ensure their old authentication sessions will cease to be valid.

Once I change the alternative id, I get a RecursionError if I try to do anything with current_user. The only way I've found to avoid it is to immediately log the current user out, but is that what I'm supposed to do? Is there some easy way I'm missing to keep the current session valid after changing the alternative id?

@mconigliaro
Copy link
Author

I'm curious whether there's some better way I'm missing, but here's something that seems to work:

if user_wants_to_regenerate_token:
    user = get_user_by_username(current_user.username)
    user.refresh_token()
    login_user(user, remember=login_remembered)

So to avoid touching current_user after refreshing the token, just create a new user object and log that one in.

Repository owner locked and limited conversation to collaborators Apr 1, 2024
@maxcountryman maxcountryman converted this issue into discussion #845 Apr 1, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant