# Implementation Guide for @mana/auth-mobile ## Overview This package contains a reusable authentication system extracted from the Storyteller mobile app. It provides a complete authentication solution for Mana Core-powered React Native apps with full customization support. ## Package Structure ``` @mana-auth-mobile/ ├── src/ │ ├── services/ # Auth and token management services │ │ ├── authService.ts # Main authentication service │ │ └── tokenManager.ts # JWT token manager with auto-refresh │ ├── components/ # UI components │ │ ├── ManaLoginScreen.tsx # Complete login/register flow │ │ ├── GoogleSignInButton.tsx # Google OAuth button │ │ └── AppleSignInButton.tsx # Apple Sign In button │ ├── contexts/ # React contexts │ │ └── ManaAuthContext.tsx # Authentication state management │ ├── utils/ # Utility functions │ │ ├── safeStorage.ts # Secure storage wrapper │ │ ├── logger.ts # Logging utilities │ │ ├── deviceManager.ts # Device identification │ │ └── networkErrorUtils.ts # Network helpers │ ├── types/ # TypeScript definitions │ │ └── index.ts # Auth-related types │ ├── config/ # Configuration system │ │ ├── types.ts # Config type definitions │ │ ├── defaults.ts # Default configurations │ │ └── ManaAuthConfigProvider.tsx # Config provider │ ├── hooks/ # React hooks │ │ └── useManaAuth.ts # Main auth hook │ └── index.ts # Package exports ├── package.json ├── tsconfig.json ├── README.md └── IMPLEMENTATION_GUIDE.md ``` ## Core Components to Implement ### 1. Services (Already Structured) The following services need to be copied from the storyteller codebase with minimal modifications: - **authService.ts**: Copy from `mobile/src/services/authService.ts` - Replace hardcoded `BACKEND_URL` with `config.environment.backendUrl` - Replace storage keys with `config.environment.storageKeys` - **tokenManager.ts**: Copy from `mobile/src/services/tokenManager.ts` - No configuration changes needed (works with authService) ### 2. Components - **ManaLoginScreen.tsx**: Copy from `mobile/app/login.tsx` - Use `useManaAuthConfig()` hook to access theme/text configuration - Replace hardcoded colors with `config.theme.colors.*` - Replace hardcoded text with `config.text.*` - Replace background image with `config.theme.backgroundImage` - **GoogleSignInButton.tsx**: Copy from `mobile/components/molecules/GoogleSignInButton.tsx` - Use `config.environment.googleClientId` - Use `config.theme.colors.googleButton` - Use `config.text.loginWithGoogle` - **AppleSignInButton.tsx**: Copy from `mobile/components/molecules/AppleSignInButton.tsx` - Use `config.environment.appleClientId` - Use `config.theme.colors.appleButton` - Use `config.text.loginWithApple` ### 3. Context (ManaAuthContext.tsx) Copy from `mobile/src/contexts/AuthContext.tsx` with these changes: - Remove Supabase-specific code (or make it optional) - Remove RevenueCat-specific code (or make it optional) - Use configuration for analytics instead of hardcoded PostHog - Export `useManaAuth` hook ### 4. Main Export (index.ts) ```typescript // Configuration export { ManaAuthConfigProvider, useManaAuthConfig } from './config/ManaAuthConfigProvider'; export * from './config/types'; // Context & Hooks export { ManaAuthProvider, useManaAuth } from './contexts/ManaAuthContext'; // Components export { default as ManaLoginScreen } from './components/ManaLoginScreen'; export { GoogleSignInButton } from './components/GoogleSignInButton'; export { AppleSignInButton } from './components/AppleSignInButton'; // Services (for advanced usage) export { authService } from './services/authService'; export { tokenManager } from './services/tokenManager'; // Types export * from './types'; ``` ## Usage in Storyteller (Example) ### Step 1: Install the Package ```bash # From the storyteller mobile directory npm install ../../../@mana-auth-mobile ``` ### Step 2: Configure in App Root ```typescript // mobile/app/_layout.tsx import { ManaAuthConfigProvider } from '@mana/auth-mobile'; export default function RootLayout() { return ( {/* Rest of your app */} ); } ``` ### Step 3: Use in Screens ```typescript // mobile/app/login.tsx import { ManaLoginScreen } from '@mana/auth-mobile'; export default function LoginScreen() { return ; } ``` ```typescript // mobile/app/(tabs)/index.tsx import { useManaAuth } from '@mana/auth-mobile'; export default function HomeScreen() { const { user, signOut } = useManaAuth(); return ( Welcome {user?.name}!