feat: prefill API key in onboarding tester from ?token= URL param#55
Merged
Conversation
83acb09 to
178dc50
Compare
When a user arrives at the onboarding tester with a `?token=<value>` query parameter, decode it (URL-safe base64, no padding) and prefill the API key input. Replace the default helper text with a note explaining the key was filled from the link so the user understands where it came from and can edit if needed. The decoder fails closed: any malformed value, decoding error, or decoded result that does not look like a printable key results in the input staying empty — a bad link can never break the page. The param read runs in a useEffect so SSR and the first client render agree (both empty); the prefill happens on the second client render with no hydration mismatch. The param is named `token` rather than `key` to make it clear at a glance that the URL value is not the user's literal API key — it's the encoded form that the page decodes.
178dc50 to
71541c1
Compare
trichardswp
approved these changes
Jun 29, 2026
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.
Summary
When a user arrives at the API onboarding tester with a
?token=<value>query parameter on the URL, decode it and prefill the API Key input. A short note explains where the key came from so the user understands the input wasn't autofilled by a password manager and can edit it if needed.Users who land on the page without the param see the page exactly as today.
Why
tokenand notkey?The URL value isn't the user's literal API key — it's the URL-safe base64 encoding of it. Naming the param
tokenkeeps that distinction obvious so a user (or anyone reading the URL) doesn't confuse the encoded value with the key itself.Token format
The value is URL-safe base64 with no padding of the key string. This format was chosen because:
atobafter the URL-safe → standard char swap and re-padding).Decoder behavior (
decodeApiKeyFromTokeninonboarding-tester.tsx):nullwhen the param is absent, malformed, fails to base64-decode, or decodes to something that doesn't look like a printable key.nullis returned, the input stays empty and the page renders exactly as it does today.\x21-\x7E) — it's there becauseatobaccepts any valid base64 including binary, and we want to reject decoded results that obviously aren't key strings.UX
When no key is prefilled, the existing helper text is unchanged:
Hydration
The URL-param read happens in a
useEffect, not inuseState's initializer, so SSR and the first client render both produce an empty input. The prefill runs on the second client render — no hydration mismatch.Test plan
/documentation/making-your-first-requestwith no query param → input is empty, default helper text shown./documentation/making-your-first-request?token=<urlsafe-base64-of-some-string>→ input is prefilled with the decoded value, prefilled helper text shown.?token=notvalid$$(malformed) → input stays empty, default helper text shown.?token=(empty) → input stays empty.?token=AAAA(decodes to four NUL bytes) → input stays empty (regex gate rejects non-printable).