-
-
Notifications
You must be signed in to change notification settings - Fork 677
feat: add optional Clerk access gate #1841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ea1d8e0
4681a1c
527d4d1
3fd834a
66eb0b7
3ef2131
ed24b5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { ClerkLoaded, ClerkLoading, ClerkProvider, Show, SignIn, UserButton } from "@clerk/react"; | ||
| import type { ReactNode } from "react"; | ||
|
|
||
| interface ClerkGateProps { | ||
| publishableKey: string; | ||
| children: ReactNode; | ||
| } | ||
|
|
||
| /** | ||
| * Optional whole-app sign-in gate for hosted web deployments. | ||
| * | ||
| * This module is dynamically imported only when a Clerk key is configured, so | ||
| * normal web, Tauri, mobile, and embedded builds do not initialize Clerk. | ||
| */ | ||
|
giswqs marked this conversation as resolved.
|
||
| export function ClerkGate({ publishableKey, children }: ClerkGateProps) { | ||
| return ( | ||
| <ClerkProvider publishableKey={publishableKey}> | ||
| <ClerkLoading> | ||
| <div className="flex min-h-screen items-center justify-center bg-background"> | ||
| <div | ||
| aria-hidden="true" | ||
| className="h-8 w-8 animate-spin rounded-full border-2 border-muted border-t-primary" | ||
| /> | ||
| </div> | ||
| </ClerkLoading> | ||
| <ClerkLoaded> | ||
| <Show when="signed-out"> | ||
| <main className="flex min-h-screen items-center justify-center bg-background p-4"> | ||
| <SignIn routing="hash" /> | ||
| </main> | ||
| </Show> | ||
| <Show when="signed-in"> | ||
|
giswqs marked this conversation as resolved.
|
||
| {children} | ||
|
giswqs marked this conversation as resolved.
|
||
| <div className="fixed end-2 top-2 z-[100]"> | ||
| <UserButton /> | ||
| </div> | ||
| </Show> | ||
|
giswqs marked this conversation as resolved.
|
||
| </ClerkLoaded> | ||
| </ClerkProvider> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { readDeploymentEnvValue, type EnvRecord } from "./deployment-env"; | ||
|
|
||
| export const CLERK_PUBLISHABLE_KEY_ENV = "VITE_GEOLIBRE_CLERK_PUBLISHABLE_KEY"; | ||
|
|
||
| /** | ||
| * Resolve the optional Clerk publishable key for a web deployment. | ||
| * | ||
| * A missing key keeps authentication completely disabled. Native and embedded | ||
| * callers should pass `false` for `webApp` so a build-time environment variable | ||
| * cannot accidentally gate an offline application. | ||
| */ | ||
| export function resolveClerkPublishableKey( | ||
| webApp: boolean, | ||
| deploymentEnv?: EnvRecord, | ||
| buildEnv?: EnvRecord, | ||
| ): string | undefined { | ||
| if (!webApp) return undefined; | ||
| return readDeploymentEnvValue(CLERK_PUBLISHABLE_KEY_ENV, deploymentEnv, buildEnv)?.trim(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -710,6 +710,10 @@ function pwaPlugin(): Plugin[] { | |
| // is auto-named `i18n-<hash>` and must stay precached, so this must NOT match | ||
| // it. English is bundled there, so it stays precached and works offline. | ||
| "**/i18n-locale-*.js", | ||
| // Optional hosted-web authentication. This chunk is requested only when a | ||
| // Clerk publishable key is configured, so public deployments should not | ||
| // download it during service-worker installation. | ||
| "**/ClerkGate-*.js", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confidence: medium. This single glob assumes the whole That's not guaranteed — this very file documents a case where it wasn't (a few lines up): the Worth confirming against the actual |
||
| ]; | ||
| // Note: the 4 KB public/pyodide/pyodide-worker.js shim is intentionally left | ||
| // in the precache (revisioned, so no stale-after-deploy risk). The heavy | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.