feat(magic-link): let the bundled views choose where a link lands - #143
Merged
Conversation
requestMagicLink(redirectUri) shipped in 0.10.0, but only the headless client path could reach it. An application using AuthRoutes had no way to set one, so the deployment-wide destination was the only option for the audience least likely to be wiring up its own client. AuthProvider takes magicLinkRedirectUri and useAuthClient hands it to the client as the default for every send. SeamlessAuthClientOptions carries the same field for a directly constructed client. The destination lives on the client rather than at each call site on purpose. The sign-in screen and the resend both send with no argument, so neither view changes here and the two cannot disagree about where the link goes. A resend landing somewhere other than the link it repeats would be a confusing failure and an easy one to miss in review. Omit it and nothing changes: the same empty body is sent and the deployment's destination still applies. An explicit argument still wins. Closes #139
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.
Closes #139
Follow-up to #138, which added
redirectUritorequestMagicLink. That wasreachable only from the headless client path, so an application using
AuthRoutesstill had no way to set a destination, which left thedeployment-wide one as the only option for the audience least likely to be
wiring up its own client.
The change
AuthProvidertakesmagicLinkRedirectUri, anduseAuthClient()hands it tothe client as the default for every send.
SeamlessAuthClientOptionscarriesthe same field, so a directly constructed client can do this too.
Why the default lives on the client
The issue flags the resend as the part to get right:
Login.sendMagicLinkandMagicLinkSent.resendboth callrequestMagicLink()with no argument, so theyagree today, and the moment one starts sending a destination and the other does
not, a resent link lands somewhere the first one did not.
Putting the destination on the client rather than at each call site means
neither view changes in this PR. Both still send with no argument, so they
cannot disagree. The alternative considered was threading it through the router
state the two views already share, but
location.statedoes not survive areload, so a refresh followed by a resend would silently fall back to the
deployment default and recreate the exact mismatch.
An explicit
requestMagicLink(uri)still wins over the configured default, soheadless callers keep per-call control.
Tests
tests/magicLinkDestination.test.tsxdrives both views through a real clientwith only
fetchmocked, and asserts the resend body is byte-identical to thefirst send. I verified it bites: pointing
MagicLinkSent.resendat a differentdestination fails it with the two bodies side by side, rather than passing
vacuously.
Also covered: the client honours its configured default, a call argument
overrides it, the hook passes the value through, and with nothing configured
both views still send
{}and keep the deployment's destination.Checks
npm run typecheck,npm run lint,npm run format:check,npm run buildandnpm run check-npm-buildall pass. 319 tests across 32 suites pass. The optionappears in the built
AuthProvider.d.tsandcreateSeamlessAuthClient.d.ts.