From bd9fbb4da52ef90a91b1ada93916850e4e500ce7 Mon Sep 17 00:00:00 2001 From: Adam Moussa <166072409+amoussa1229@users.noreply.github.com> Date: Wed, 20 May 2026 12:14:29 -0400 Subject: [PATCH] Fix launch crash: lazy-load amazon-cognito-identity-js The library's module graph eagerly initializes native module bindings (RNAWSCognito) during import, causing a TypeError on startup since the native pod isn't linked. Dynamic import defers loading until the user actually taps "Sign In" with credentials, keeping it off the critical startup path entirely. --- mobile/src/lib/api/cognito-auth.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/mobile/src/lib/api/cognito-auth.ts b/mobile/src/lib/api/cognito-auth.ts index 5bf13db..de78e3f 100644 --- a/mobile/src/lib/api/cognito-auth.ts +++ b/mobile/src/lib/api/cognito-auth.ts @@ -1,16 +1,6 @@ -import { - CognitoUserPool, - CognitoUser, - AuthenticationDetails, - CognitoUserSession, -} from 'amazon-cognito-identity-js'; +import type { CognitoUserSession } from 'amazon-cognito-identity-js'; import Config from '../../config'; -const userPool = new CognitoUserPool({ - UserPoolId: Config.COGNITO_USER_POOL_ID, - ClientId: Config.COGNITO_CLIENT_ID, -}); - export interface CognitoTokens { accessToken: string; idToken: string; @@ -28,10 +18,22 @@ function extractTokens(session: CognitoUserSession): CognitoTokens { }; } -export function authenticateWithCredentials( +export async function authenticateWithCredentials( email: string, password: string, ): Promise { + // Lazy-load to keep amazon-cognito-identity-js out of the startup module graph + const { + CognitoUserPool, + CognitoUser, + AuthenticationDetails, + } = await import('amazon-cognito-identity-js'); + + const userPool = new CognitoUserPool({ + UserPoolId: Config.COGNITO_USER_POOL_ID, + ClientId: Config.COGNITO_CLIENT_ID, + }); + return new Promise((resolve, reject) => { const cognitoUser = new CognitoUser({ Username: email,