/// /** * Personal Google Auth Wrapper * * Wraps the base google-auth pattern and adds the #googleAuthPersonal tag. * Use this when you want to explicitly mark an auth as "personal". * * Can be used two ways: * 1. Pre-hoc: Create this directly, log in, and favorite * 2. Post-hoc: Created by google-auth-switcher after login */ import { computed, Default, ifElse, NAME, pattern, UI } from "commontools"; import GoogleAuth, { Auth, createPreviewUI, SelectedScopes, } from "./google-auth.tsx"; interface Input { selectedScopes: Default; auth: Default< Auth, { token: ""; tokenType: ""; scope: []; expiresIn: 0; expiresAt: 0; refreshToken: ""; user: { email: ""; name: ""; picture: "" }; } >; } /** Personal Google account. #googleAuth #googleAuthPersonal */ interface Output { auth: Auth; accountType: "personal"; /** Minimal preview for picker display with PERSONAL badge */ previewUI: unknown; } export default pattern(({ auth, selectedScopes }) => { // Compose the base GoogleAuth pattern const baseAuth = GoogleAuth({ auth, selectedScopes }); // Enhanced preview with PERSONAL badge using shared helper // Build scopes record manually (same pattern as google-auth.tsx to avoid type casting) const previewUI = computed(() => createPreviewUI( baseAuth.auth, { gmail: selectedScopes.gmail, gmailSend: selectedScopes.gmailSend, gmailModify: selectedScopes.gmailModify, calendar: selectedScopes.calendar, calendarWrite: selectedScopes.calendarWrite, drive: selectedScopes.drive, docs: selectedScopes.docs, contacts: selectedScopes.contacts, }, { text: "PERSONAL", color: "#3b82f6" }, ) ); return { [NAME]: computed(() => `Google Auth (Personal)${ baseAuth.auth?.user?.email ? ` - ${baseAuth.auth.user.email}` : "" }` ), [UI]: ( {/* Account type badge */} PERSONAL {computed(() => baseAuth.auth?.user?.email || "Not logged in")} {/* Embed the base auth UI */} {baseAuth as any} {/* Prominent favorite CTA - only show when logged in */} {ifElse( computed(() => !!baseAuth.auth?.user?.email), Favorite This Piece! Click the star to save your personal Google auth Patterns can then find it via{" "} #googleAuthPersonal , null, )} ), auth: baseAuth.auth, accountType: "personal" as const, previewUI, }; });
Click the star to save your personal Google auth
Patterns can then find it via{" "} #googleAuthPersonal
#googleAuthPersonal