Fix launch crash: lazy-load amazon-cognito-identity-js
Some checks are pending
Deploy Mobile (iOS) / Build & Upload to TestFlight (push) Waiting to run
Deploy / Deploy to AWS (push) Waiting to run

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.
This commit is contained in:
Adam Moussa 2026-05-20 12:14:29 -04:00
parent a9c157dc95
commit bd9fbb4da5

View file

@ -1,16 +1,6 @@
import { import type { CognitoUserSession } from 'amazon-cognito-identity-js';
CognitoUserPool,
CognitoUser,
AuthenticationDetails,
CognitoUserSession,
} from 'amazon-cognito-identity-js';
import Config from '../../config'; import Config from '../../config';
const userPool = new CognitoUserPool({
UserPoolId: Config.COGNITO_USER_POOL_ID,
ClientId: Config.COGNITO_CLIENT_ID,
});
export interface CognitoTokens { export interface CognitoTokens {
accessToken: string; accessToken: string;
idToken: string; idToken: string;
@ -28,10 +18,22 @@ function extractTokens(session: CognitoUserSession): CognitoTokens {
}; };
} }
export function authenticateWithCredentials( export async function authenticateWithCredentials(
email: string, email: string,
password: string, password: string,
): Promise<CognitoTokens> { ): Promise<CognitoTokens> {
// 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) => { return new Promise((resolve, reject) => {
const cognitoUser = new CognitoUser({ const cognitoUser = new CognitoUser({
Username: email, Username: email,