Always return new user token for JWT callback to use #1783
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
As @riccardobl mentioned in #1781, #1779 is caused by the cookie pointer update in
pubkeyAuth
getting overridden back to the initial cookie pointer in the JWT callback.As I mentioned in #1779 (comment), I thought I fixed this in #1618 but it appears that I didn't really test all cases, but only the case when we switched to anon and then try to add a new account. Then we automatically get switched because the JWT callback will run with the token set to the new user since we return the new user token (the variable that is called
user
) inpubkeyAuth
, not the old user token (the variable that is calledtoken
).However, as noticed in #1779, this does not work if you're logged in as some account and then add an account because we then return
token
(the old user). This is what I must have broken in #1618 and @riccardobl fixed in #1781. However, #1781 then breaks switching from anon to a new account becausesetMultiAuthCookies
will not be called inpubkeyAuth
and in the JWT callback.Since the token that the JWT callback receives is the token we returned in
pubkeyAuth
, returning the token of the user we want to switch to inpubkeyAuth
makes sure that the JWT callback will callsetMultiAuthCookies
with the token we want. So afaict, we don't actually need to set the cookie pointer inpubkeyAuth
but can rely on the JWT callback to do this for us. This is what this PR does.fix #1779 supersedes #1781
Videos
switching around to new accounts:
2024-12-31.02-53-15.mp4
switching around to existing accounts:
2024-12-31.03-03-51.mp4
unlinking + linking new nostr key:
2024-12-31.03-20-36.mp4
Checklist
Are your changes backwards compatible? Please answer below:
yes
On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:
7
. It was a little tricky to consider all cases and make sense of them but I've tested all cases afaict now as can be seen in the videos and all make sense to me now. Simply return token we want to switch to and let JWT callback set the cookies. We only need to consider account switching inpubkeyAuth
to not accidentally update pubkeys when we instead wanted to switch accounts.For frontend changes: Tested on mobile, light and dark mode? Please answer below:
n/a
Did you introduce any new environment variables? If so, call them out explicitly here:
no