@umituz/react-native-auth 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +6 -0
- package/src/infrastructure/services/AuthService.ts +6 -3
- package/src/presentation/components/LoginForm.tsx +3 -1
- package/src/presentation/components/RegisterForm.tsx +3 -1
- package/src/presentation/hooks/useAuth.ts +1 -0
- package/src/presentation/utils/getAuthErrorMessage.ts +78 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -74,3 +74,9 @@ export type {
|
|
|
74
74
|
export { AuthLegalLinks } from './presentation/components/AuthLegalLinks';
|
|
75
75
|
export type { AuthLegalLinksProps } from './presentation/components/AuthLegalLinks';
|
|
76
76
|
|
|
77
|
+
// =============================================================================
|
|
78
|
+
// PRESENTATION LAYER - Utilities
|
|
79
|
+
// =============================================================================
|
|
80
|
+
|
|
81
|
+
export { getAuthErrorLocalizationKey } from './presentation/utils/getAuthErrorMessage';
|
|
82
|
+
|
|
@@ -96,9 +96,6 @@ function mapFirebaseAuthError(error: any): Error {
|
|
|
96
96
|
if (code === "auth/invalid-email") {
|
|
97
97
|
return new AuthInvalidEmailError();
|
|
98
98
|
}
|
|
99
|
-
if (code === "auth/operation-not-allowed") {
|
|
100
|
-
return new AuthConfigurationError("Email/password authentication is not enabled");
|
|
101
|
-
}
|
|
102
99
|
if (code === "auth/weak-password") {
|
|
103
100
|
return new AuthWeakPasswordError();
|
|
104
101
|
}
|
|
@@ -117,6 +114,12 @@ function mapFirebaseAuthError(error: any): Error {
|
|
|
117
114
|
if (code === "auth/too-many-requests") {
|
|
118
115
|
return new AuthError("Too many requests. Please try again later.", "AUTH_TOO_MANY_REQUESTS");
|
|
119
116
|
}
|
|
117
|
+
if (code === "auth/configuration-not-found" || code === "auth/app-not-authorized") {
|
|
118
|
+
return new AuthConfigurationError("Authentication is not properly configured. Please contact support.");
|
|
119
|
+
}
|
|
120
|
+
if (code === "auth/operation-not-allowed") {
|
|
121
|
+
return new AuthConfigurationError("Email/password authentication is not enabled. Please contact support.");
|
|
122
|
+
}
|
|
120
123
|
|
|
121
124
|
return new AuthError(message, code);
|
|
122
125
|
}
|
|
@@ -11,6 +11,7 @@ import { useAuth } from "../hooks/useAuth";
|
|
|
11
11
|
import { AuthErrorDisplay } from "./AuthErrorDisplay";
|
|
12
12
|
import { AuthDivider } from "./AuthDivider";
|
|
13
13
|
import { AuthLink } from "./AuthLink";
|
|
14
|
+
import { getAuthErrorLocalizationKey } from "../utils/getAuthErrorMessage";
|
|
14
15
|
|
|
15
16
|
interface LoginFormProps {
|
|
16
17
|
onNavigateToRegister: () => void;
|
|
@@ -73,7 +74,8 @@ export const LoginForm: React.FC<LoginFormProps> = ({
|
|
|
73
74
|
try {
|
|
74
75
|
await signIn(email.trim(), password);
|
|
75
76
|
} catch (err: any) {
|
|
76
|
-
const
|
|
77
|
+
const localizationKey = getAuthErrorLocalizationKey(err);
|
|
78
|
+
const errorMessage = t(localizationKey);
|
|
77
79
|
setLocalError(errorMessage);
|
|
78
80
|
}
|
|
79
81
|
};
|
|
@@ -17,6 +17,7 @@ import { useAuth } from "../hooks/useAuth";
|
|
|
17
17
|
import { AuthErrorDisplay } from "./AuthErrorDisplay";
|
|
18
18
|
import { AuthLink } from "./AuthLink";
|
|
19
19
|
import { AuthLegalLinks } from "./AuthLegalLinks";
|
|
20
|
+
import { getAuthErrorLocalizationKey } from "../utils/getAuthErrorMessage";
|
|
20
21
|
|
|
21
22
|
interface RegisterFormProps {
|
|
22
23
|
onNavigateToLogin: () => void;
|
|
@@ -121,7 +122,8 @@ export const RegisterForm: React.FC<RegisterFormProps> = ({
|
|
|
121
122
|
displayName.trim() || undefined,
|
|
122
123
|
);
|
|
123
124
|
} catch (err: any) {
|
|
124
|
-
const
|
|
125
|
+
const localizationKey = getAuthErrorLocalizationKey(err);
|
|
126
|
+
const errorMessage = t(localizationKey);
|
|
125
127
|
setLocalError(errorMessage);
|
|
126
128
|
}
|
|
127
129
|
};
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { useEffect, useState, useCallback } from "react";
|
|
7
7
|
import type { User } from "firebase/auth";
|
|
8
8
|
import { getAuthService } from "../../infrastructure/services/AuthService";
|
|
9
|
+
import { getAuthErrorLocalizationKey } from "../utils/getAuthErrorMessage";
|
|
9
10
|
|
|
10
11
|
export interface UseAuthResult {
|
|
11
12
|
/** Current authenticated user */
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get localized error message from AuthError
|
|
3
|
+
* Maps error codes to localization keys
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { AuthError } from "../../domain/errors/AuthError";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Map AuthError code to localization key
|
|
10
|
+
*/
|
|
11
|
+
export function getAuthErrorLocalizationKey(error: Error): string {
|
|
12
|
+
// Check if error has code property
|
|
13
|
+
const code = (error as any).code;
|
|
14
|
+
|
|
15
|
+
// Map error codes to localization keys
|
|
16
|
+
const errorCodeMap: Record<string, string> = {
|
|
17
|
+
AUTH_INVALID_EMAIL: "auth.errors.invalidEmail",
|
|
18
|
+
AUTH_WEAK_PASSWORD: "auth.errors.weakPassword",
|
|
19
|
+
AUTH_USER_NOT_FOUND: "auth.errors.userNotFound",
|
|
20
|
+
AUTH_WRONG_PASSWORD: "auth.errors.wrongPassword",
|
|
21
|
+
AUTH_EMAIL_ALREADY_IN_USE: "auth.errors.emailAlreadyInUse",
|
|
22
|
+
AUTH_NETWORK_ERROR: "auth.errors.networkError",
|
|
23
|
+
AUTH_CONFIG_ERROR: "auth.errors.configurationError",
|
|
24
|
+
AUTH_TOO_MANY_REQUESTS: "auth.errors.tooManyRequests",
|
|
25
|
+
AUTH_USER_DISABLED: "auth.errors.userDisabled",
|
|
26
|
+
AUTH_NOT_INITIALIZED: "auth.errors.authNotInitialized",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Check error name for specific error types
|
|
30
|
+
if (error.name === "AuthInvalidEmailError") {
|
|
31
|
+
return "auth.errors.invalidEmail";
|
|
32
|
+
}
|
|
33
|
+
if (error.name === "AuthWeakPasswordError") {
|
|
34
|
+
return "auth.errors.weakPassword";
|
|
35
|
+
}
|
|
36
|
+
if (error.name === "AuthUserNotFoundError") {
|
|
37
|
+
return "auth.errors.userNotFound";
|
|
38
|
+
}
|
|
39
|
+
if (error.name === "AuthWrongPasswordError") {
|
|
40
|
+
return "auth.errors.wrongPassword";
|
|
41
|
+
}
|
|
42
|
+
if (error.name === "AuthEmailAlreadyInUseError") {
|
|
43
|
+
return "auth.errors.emailAlreadyInUse";
|
|
44
|
+
}
|
|
45
|
+
if (error.name === "AuthNetworkError") {
|
|
46
|
+
return "auth.errors.networkError";
|
|
47
|
+
}
|
|
48
|
+
if (error.name === "AuthConfigurationError") {
|
|
49
|
+
return "auth.errors.configurationError";
|
|
50
|
+
}
|
|
51
|
+
if (error.name === "AuthInitializationError") {
|
|
52
|
+
return "auth.errors.authNotInitialized";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Use code if available
|
|
56
|
+
if (code && errorCodeMap[code]) {
|
|
57
|
+
return errorCodeMap[code];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Check error message for specific patterns
|
|
61
|
+
const message = error.message.toLowerCase();
|
|
62
|
+
if (message.includes("too many requests")) {
|
|
63
|
+
return "auth.errors.tooManyRequests";
|
|
64
|
+
}
|
|
65
|
+
if (message.includes("user account has been disabled") || message.includes("user disabled")) {
|
|
66
|
+
return "auth.errors.userDisabled";
|
|
67
|
+
}
|
|
68
|
+
if (message.includes("not properly configured") || message.includes("configuration")) {
|
|
69
|
+
return "auth.errors.configurationError";
|
|
70
|
+
}
|
|
71
|
+
if (message.includes("not enabled") || message.includes("operation not allowed")) {
|
|
72
|
+
return "auth.errors.operationNotAllowed";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Default to unknown error
|
|
76
|
+
return "auth.errors.unknownError";
|
|
77
|
+
}
|
|
78
|
+
|