Allow anonymous users to read lessons (sign-in CTA for actions + shell)#10
Allow anonymous users to read lessons (sign-in CTA for actions + shell)#10Copilot wants to merge 6 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Append a hash fragment to the OAuth callbackURL so the browser scrolls to the triggering button after the sign-in redirect completes. - RunBlock: useId() generates a stable per-instance id placed on the container div; the fragment is encodeURIComponent'd to handle the colon chars React inserts (:r0:, etc.). - CheckCard: the check's own id (already used as data-check-id) is promoted to the HTML id attribute and appended as-is (check ids are plain alphanumeric slugs, no encoding needed).
Done in f39dbc8. Each CTA now appends a hash fragment to the
|
exekias
left a comment
There was a problem hiding this comment.
Buttons don't work anymore, also the cursor doesn't change to the hand when hovering
The previous approach of embedding a hash fragment directly in the OAuth callbackURL (/lessons/slug#%3Ar0%3A) caused better-auth to silently reject the sign-in request, making the buttons appear to do nothing. The cursor was also missing because the classes lacked cursor-pointer. Changes: - Add ScrollToAnchor client component that reads a stored anchor ID from sessionStorage on mount and scrolls to the element - RunBlock: strip colons from useId() output (r0 instead of :r0:) so the HTML id is a safe URL fragment; call storeScrollAnchor() before signIn.social() instead of embedding the hash in the URL; add cursor-pointer to both Run and Sign-in-to-run buttons - CheckCard: same pattern — storeScrollAnchor(check.id) before the redirect; add cursor-pointer to both Check and Sign-in-to-check buttons - Lesson page: render <ScrollToAnchor /> so the stored anchor is consumed after the OAuth redirect lands back on the lesson
exekias
left a comment
There was a problem hiding this comment.
almost there, I want to see the hand cursor also on the shell button
Fixed in 6a5a938 — added |
Lesson pages currently redirect unauthenticated visitors to
/. This removes that gate so anyone can read lesson prose, while keeping every interactive action behind auth — surfaced in-context rather than as a hard redirect.Changes
app/lessons/[slug]/page.tsx— dropif (!session) redirect("/"). Session is now optional;passedCheckIdsshort-circuits to an empty set for anonymous users.isSignedInandcallbackURL(/lessons/<slug>) are threaded into component builders.app/sign-in-button.tsx— accept optionalcallbackURLprop (default:"/dashboard") so CTAs can return users to the lesson they were reading.components/lesson/mdx-components.tsx—buildLessonComponentsnow acceptsisSignedIn: booleanandcallbackURL: string, forwarded toRunBlockandCheckCard.components/lesson/RunBlock.tsx— swaps the ▶ Run button for a compact "Sign in to run" trigger when!isSignedIn. UsesuseId()to assign a stableidto the container; the OAuthcallbackURLincludes a hash fragment (#<encoded-id>) so the browser scrolls back to the block after sign-in.components/lesson/Check.tsx— swaps the Check button for "Sign in to check" when!isSignedIn. The check's ownidis promoted to the HTMLidattribute on the<aside>; the OAuthcallbackURLincludes#<check-id>so the browser scrolls back to the check card after sign-in.components/lesson/SandboxSection.tsx—userIdis nowstring | undefined; when absent, renders the unauthenticated panel and skipsensureBranchForLessonentirely (no Xata branch created for anonymous visitors).components/lesson/BranchPanel.tsx— addskind="unauthenticated"variant: a short message +<SignInButton callbackURL={lessonPath} />.API routes retain their existing
401guards unchanged.