/// /** * Google Auth Switcher - Post-hoc Classification * * This pattern allows users to: * 1. Log in with any Google account * 2. AFTER seeing their email, classify it as "Personal" or "Work" * 3. Creates a wrapper pattern with the right tags and navigates to it * * Better UX than pre-hoc: user sees actual email before classifying. */ import { computed, Default, handler, NAME, navigateTo, pattern, UI, Writable, } from "commontools"; import GoogleAuth, { Auth } from "../google-auth.tsx"; import GoogleAuthPersonal from "../google-auth-personal.tsx"; import GoogleAuthWork from "../google-auth-work.tsx"; // Same selected scopes type as base GoogleAuth type SelectedScopes = { gmail: Default; gmailSend: Default; gmailModify: Default; calendar: Default; calendarWrite: Default; drive: Default; docs: Default; contacts: Default; }; interface Input { selectedScopes: Default< SelectedScopes, { gmail: true; gmailSend: false; gmailModify: false; calendar: true; calendarWrite: false; drive: false; docs: false; contacts: false; } >; auth: Default< Auth, { token: ""; tokenType: ""; scope: []; expiresIn: 0; expiresAt: 0; refreshToken: ""; user: { email: ""; name: ""; picture: "" }; } >; } /** Google account switcher for choosing personal/work accounts. #googleAuthSwitcher */ interface Output { auth: Auth; } // Handler to create personal wrapper and navigate to it const createPersonalWrapper = handler< unknown, { auth: Writable; selectedScopes: Writable } >((_, { auth, selectedScopes }) => { const wrapper = GoogleAuthPersonal({ auth, selectedScopes }); return navigateTo(wrapper); }); // Handler to create work wrapper and navigate to it const createWorkWrapper = handler< unknown, { auth: Writable; selectedScopes: Writable } >((_, { auth, selectedScopes }) => { const wrapper = GoogleAuthWork({ auth, selectedScopes }); return navigateTo(wrapper); }); export default pattern(({ auth, selectedScopes }) => { // Compose the base GoogleAuth pattern const baseAuth = GoogleAuth({ auth, selectedScopes }); // Check if logged in const isLoggedIn = computed(() => !!baseAuth.auth?.user?.email); const userEmail = computed(() => baseAuth.auth?.user?.email || ""); return { [NAME]: computed(() => baseAuth.auth?.user?.email ? `Google Auth Setup - ${baseAuth.auth.user.email}` : "Google Auth Setup" ), [UI]: (
{/* CLASSIFICATION CTA - Show at TOP after login */} {computed(() => isLoggedIn ? (

What type of account is this?

Logged in as: {userEmail}

This will create a tagged wrapper and navigate you there to favorite.

) : null )} {/* Embed base auth UI */} {baseAuth as any}
), auth: baseAuth.auth, }; });