mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-09-30 06:33:13 +00:00
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.
This commit is contained in:
parent
a9c157dc95
commit
bd9fbb4da5
1 changed files with 14 additions and 12 deletions
|
|
@ -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,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue