Skip to content

feat: login by passing API token in URL #hash#1875

Draft
yusefnapora wants to merge 2 commits intochore/refactor-frontend-api-methodsfrom
feat/auth-in-hash-fragment
Draft

feat: login by passing API token in URL #hash#1875
yusefnapora wants to merge 2 commits intochore/refactor-frontend-api-methodsfrom
feat/auth-in-hash-fragment

Conversation

@yusefnapora
Copy link
Contributor

This adds the ability to set the URL hash to #authToken=<your-api-key> and use it to authenticate to the API.

It adds a /user/meta route to return the issuer and publicAddress, which we were previously getting from getMagic().user.getMetadata().

The "is logged in" check in _app.js was previously using getMetadata() to set the user object that gets passed through to UserContext. Since we can no longer assume that all logged in users will have a valid magic link session, I had to add a server route to return similar data (issuer and publicAddress).

Stores the token from the fragment in localStorage, so we can clear the fragment and keep accessing the token. Maybe sessionStorage is more appropriate? I forget when to use which, lol.

This probably needs some cleanup, and it's branched off of #1864, so it's a draft for now.

@redaphid will you play with this next week? I probably won't have time to work on it, but I can answer any questions you might have.

To use it with the test user in the local development env, follow this link while the dev server is running from this branch (assuming it's on the default port).

@cloudflare-workers-and-pages
Copy link

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8622dd1
Status: ✅  Deploy successful!
Preview URL: https://f699041c.nft-storage-1at.pages.dev

View logs

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.

1 participant