chore: refactor frontend API client methods & add doc comments#1864
Open
yusefnapora wants to merge 10 commits intomainfrom
Open
chore: refactor frontend API client methods & add doc comments#1864yusefnapora wants to merge 10 commits intomainfrom
yusefnapora wants to merge 10 commits intomainfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1864 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 5 5
Lines 1242 1242
=========================================
Hits 1242 1242 Continue to review full report at Codecov.
|
Deploying with
|
| Latest commit: |
48b0a1d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://9c129a28.nft-storage-1at.pages.dev |
hugomrdias
suggested changes
Apr 29, 2022
Contributor
hugomrdias
left a comment
There was a problem hiding this comment.
LGTM just one console.log leftover
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This refactors a few things related to the frontend login flow that I found awkward while reading through the code. I'm definitely open to suggestions / change requests if anyone thinks I've made things worse :)
The major changes:
getTokenfromapi.jshas been renamed togetMagicUserToken, since there's a billion things called "token" in this codebase. Since this method only ever returns magic.link user id tokens, I gave it a more specific name, and also moved it tomagic.js, since it's magic.link specific. Also renamed some of the global state vars related to saving the token to be more specific (e.g.LIFESPAN=>MAGIC_USER_TOKEN_LIFESPAN_SEC).isLoggedIngot renamed togetMagicUserMetadata, since that's what it actually does, and a function calledisSomethingthat doesn't return a boolean is surprising.logoutMagicSessionfunction, so the logout component doesn't need direct access to the magic SDK instancegetMagicaccessor internal tomagic.jsgetStorageClientaccessor toapi.jsthat returns an authenticatedNFTStorageinstance (using the key fromgetMagicUserToken).APIconstant and thegetTokenfunctions, which were only used to new up client instances in UI codeI also refactored almost all of the functions in
api.jsto remove copy/paste boilerplatefetchRoutehelper that appends the route path to the API base url, sets theContent-Typeto json, and unpacks the JSON response bodyfetchAuthenticatedalso sets the auth header to the value ofgetMagicUserToken@redaphid would you mind checking this out and let me know if there's anything surprising?