Skip to content
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

Remove the access token from Redux & context #30275

Merged
merged 1 commit into from
May 22, 2024

Conversation

renchap
Copy link
Sponsor Member

@renchap renchap commented May 13, 2024

This is not mutable once initially loaded, and it does not make sense to store it into Redux, and this makes it easy to expose it (when dumping the Redux content for troubleshooting, dev extension…).

It is also very unpractical to require access to store.getState to make an API request where the only thing you need is the token.

This PR:

  • disallows access_token to be stored in Redux
  • removes access_token from the identity context (this was not used)
  • creates a new getAccessToken accessor from the initial state
  • changes all the places using accessToken to use the new function
  • changes the api(getState) interface to api(), and update all the callsites

@ClearlyClaire
Copy link
Contributor

That looks good, but also, wouldn't it make it even harder for the WebUI to ever handle multiple accounts at once?

@renchap
Copy link
Sponsor Member Author

renchap commented May 13, 2024

That looks good, but also, wouldn't it make it even harder for the WebUI to ever handle multiple accounts at once?

Yes, but if we go with multiple accounts I am not sure we want to do it on the fly, but probably reload the whole page using the identity of the other account. In any case, I dont think this would belong to Redux (because we do API calls outside of a component tree), and we can do it in alternate ways.

@renchap renchap marked this pull request as ready for review May 14, 2024 09:15
@renchap renchap requested a review from a team May 19, 2024 17:06
Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

@renchap renchap force-pushed the no-access-token-in-redux branch 2 times, most recently from 8e219e1 to a495f07 Compare May 19, 2024 19:52
Copy link
Contributor

This pull request has resolved merge conflicts and is ready for review.

Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

This is not mutable once initially loaded, and it does not make sense to store it into Redux, and this makes it easy to expose it (when dumping the Redux content for troubleshooting, dev extension…).

It is also very unpractical to require access to `store.getState` to make an API request where the only thing you need is the token.

This PR:
- disallows `access_token` to be stored in Redux
- removes `access_token` from the identity context (this was not used)
- creates a new `getAccessToken` accessor from the initial state
- changes all the places using `accessToken` to use the new function
- changes the `api(getState)` interface to `api()`, and update all the callsites
Copy link
Contributor

This pull request has resolved merge conflicts and is ready for review.

@renchap renchap added this pull request to the merge queue May 22, 2024
Merged via the queue into mastodon:main with commit 2c5ab8f May 22, 2024
29 checks passed
@renchap renchap deleted the no-access-token-in-redux branch May 22, 2024 14:50
renchap added a commit to renchap/mastodon that referenced this pull request May 22, 2024
When in the admin panel, calls to the API should not pass an `authorization` token, because the token is not valid for this scope. They should not pass a token, so the cookie authentication is used and they have access to the full scope.

I prefered a `withAuthorization` parameter rather than `skipAuthorization`, so the callsite is `api(false)` rather than `api(true)` when you dont want to use the token.

This was introduced in mastodon#30275
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.

None yet

2 participants