rn-swiftauth-sdk 1.0.1 → 1.0.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/README.md +147 -374
- package/dist/components/LoginForm.js +19 -11
- package/dist/components/SignUpForm.js +17 -16
- package/dist/core/AuthProvider.js +45 -75
- package/dist/types/auth.types.d.ts +11 -3
- package/dist/types/auth.types.js +0 -1
- package/dist/types/error.types.d.ts +10 -1
- package/dist/types/error.types.js +16 -1
- package/package.json +1 -1
- package/src/components/LoginForm.tsx +21 -12
- package/src/components/SignUpForm.tsx +20 -31
- package/src/core/AuthProvider.tsx +67 -116
- package/src/types/auth.types.ts +20 -17
- package/src/types/error.types.ts +20 -1
package/src/types/auth.types.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import { AuthError } from './error.types';
|
|
3
|
-
import { AuthConfig } from './config.types'; // Import config type
|
|
1
|
+
import { AuthConfig } from './config.types';
|
|
2
|
+
import { AuthError } from './error.types';
|
|
4
3
|
|
|
5
|
-
// The specific states requested in the task
|
|
6
4
|
export enum AuthStatus {
|
|
7
5
|
AUTHENTICATED = 'AUTHENTICATED',
|
|
8
6
|
UNAUTHENTICATED = 'UNAUTHENTICATED',
|
|
9
7
|
TOKEN_EXPIRED = 'TOKEN_EXPIRED',
|
|
10
|
-
LOADING = 'LOADING',
|
|
8
|
+
LOADING = 'LOADING',
|
|
11
9
|
}
|
|
12
10
|
|
|
13
11
|
export interface User {
|
|
@@ -19,25 +17,30 @@ export interface User {
|
|
|
19
17
|
token?: string;
|
|
20
18
|
}
|
|
21
19
|
|
|
20
|
+
// Input Interfaces (The "Options Pattern")
|
|
21
|
+
export interface EmailSignInOptions {
|
|
22
|
+
email: string;
|
|
23
|
+
password: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface EmailSignUpOptions {
|
|
27
|
+
email: string;
|
|
28
|
+
password: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
22
31
|
export interface AuthContextType {
|
|
23
32
|
user: User | null;
|
|
24
33
|
status: AuthStatus;
|
|
25
|
-
|
|
26
|
-
// ✅
|
|
27
|
-
isLoading: boolean;
|
|
28
|
-
|
|
29
|
-
error: AuthError | null;
|
|
30
|
-
|
|
31
|
-
// ✅ NEW: Expose config so UI components can check feature flags (e.g. enableGoogle)
|
|
34
|
+
isLoading: boolean;
|
|
35
|
+
error: AuthError | null; // ✅ Uses the type imported from error.types.ts
|
|
32
36
|
config: AuthConfig;
|
|
33
37
|
|
|
34
|
-
//
|
|
35
|
-
signInWithEmail: (
|
|
36
|
-
signUpWithEmail: (
|
|
38
|
+
// Function Signatures
|
|
39
|
+
signInWithEmail: (options: EmailSignInOptions) => Promise<void>;
|
|
40
|
+
signUpWithEmail: (options: EmailSignUpOptions) => Promise<void>;
|
|
41
|
+
|
|
37
42
|
signInWithGoogle: () => Promise<void>;
|
|
38
43
|
signInWithApple: () => Promise<void>;
|
|
39
44
|
signOut: () => Promise<void>;
|
|
40
|
-
|
|
41
|
-
// Reset error state
|
|
42
45
|
clearError: () => void;
|
|
43
46
|
}
|
package/src/types/error.types.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
// src/types/error.types.ts
|
|
2
2
|
|
|
3
|
+
// ✅ 1. Define Known Error Codes (Source of Truth)
|
|
4
|
+
export enum ProviderErrorCodes {
|
|
5
|
+
// Firebase specific
|
|
6
|
+
USER_TOKEN_EXPIRED = 'auth/user-token-expired',
|
|
7
|
+
NULL_USER = 'auth/null-user',
|
|
8
|
+
|
|
9
|
+
// Google specific
|
|
10
|
+
GOOGLE_CANCELLED = 'SIGN_IN_CANCELLED',
|
|
11
|
+
GOOGLE_IN_PROGRESS = 'IN_PROGRESS',
|
|
12
|
+
GOOGLE_PLAY_UNAVAILABLE = 'PLAY_SERVICES_NOT_AVAILABLE',
|
|
13
|
+
|
|
14
|
+
// Apple specific
|
|
15
|
+
APPLE_CANCELLED = 'ERR_REQUEST_CANCELED',
|
|
16
|
+
APPLE_NOT_SUPPORTED = 'APPLE_SIGN_IN_NOT_SUPPORTED'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Legacy error codes used in mapping (Keep this for backward compatibility if needed)
|
|
3
20
|
export enum AuthErrorCode {
|
|
4
21
|
INVALID_CREDENTIALS = 'auth/invalid-credentials',
|
|
5
22
|
USER_NOT_FOUND = 'auth/user-not-found',
|
|
@@ -24,8 +41,10 @@ export enum AuthErrorCode {
|
|
|
24
41
|
APPLE_SIGN_IN_NOT_SUPPORTED = 'APPLE_SIGN_IN_NOT_SUPPORTED',
|
|
25
42
|
}
|
|
26
43
|
|
|
44
|
+
// ✅ 2. Strong Typing for Error Objects
|
|
45
|
+
// We allow 'code' to be either our new Enum or the legacy Enum
|
|
27
46
|
export interface AuthError {
|
|
28
|
-
code: AuthErrorCode;
|
|
47
|
+
code: string | ProviderErrorCodes | AuthErrorCode;
|
|
29
48
|
message: string;
|
|
30
49
|
originalError?: any; // To store the raw Firebase error for debugging
|
|
31
50
|
}
|