rn-swiftauth-sdk 1.0.2 → 1.0.4
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 +235 -35
- package/dist/components/LoginForm.js +74 -29
- package/dist/core/AuthProvider.js +44 -49
- package/dist/errors/errorMapper.d.ts +10 -2
- package/dist/errors/errorMapper.js +61 -99
- package/dist/errors/exceptions.d.ts +82 -0
- package/dist/errors/exceptions.js +134 -0
- package/dist/errors/index.d.ts +2 -1
- package/dist/errors/index.js +19 -15
- package/dist/types/auth.types.d.ts +3 -2
- package/dist/types/error.types.d.ts +9 -8
- package/dist/types/error.types.js +22 -15
- package/package.json +1 -1
- package/src/components/LoginForm.tsx +128 -48
- package/src/core/AuthProvider.tsx +75 -65
- package/src/errors/errorMapper.ts +97 -105
- package/src/errors/exceptions.ts +174 -0
- package/src/errors/index.ts +22 -1
- package/src/types/auth.types.ts +3 -3
- package/src/types/error.types.ts +29 -21
|
@@ -1,124 +1,86 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// swiftauth-sdk/src/errors/errorMapper.ts
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapFirebaseError = void 0;
|
|
4
|
+
exports.getErrorMessage = exports.isAuthException = exports.mapFirebaseError = void 0;
|
|
5
|
+
const exceptions_1 = require("./exceptions");
|
|
4
6
|
const types_1 = require("../types");
|
|
5
7
|
const mapFirebaseError = (error) => {
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
// If it's not a Firebase error, return generic
|
|
8
|
+
// If it's already our custom exception, return it
|
|
9
|
+
if (error instanceof exceptions_1.AuthException) {
|
|
10
|
+
return error;
|
|
11
|
+
}
|
|
12
|
+
// If it's not a Firebase error or doesn't have a code, return generic
|
|
13
13
|
if (!error || typeof error.code !== 'string') {
|
|
14
|
-
return
|
|
15
|
-
...fallbackError,
|
|
16
|
-
message: error?.message || fallbackError.message
|
|
17
|
-
};
|
|
14
|
+
return new exceptions_1.UnknownAuthException(error?.message || 'An unexpected error occurred', error);
|
|
18
15
|
}
|
|
19
16
|
const fbError = error;
|
|
17
|
+
// Map Firebase error codes to custom exceptions
|
|
20
18
|
switch (fbError.code) {
|
|
21
|
-
//
|
|
19
|
+
// Invalid Credentials
|
|
22
20
|
case 'auth/invalid-email':
|
|
23
|
-
case 'auth/user-not-found':
|
|
24
21
|
case 'auth/wrong-password':
|
|
25
22
|
case 'auth/invalid-credential':
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
case 'auth/user-disabled':
|
|
24
|
+
return new exceptions_1.InvalidCredentialsException(error);
|
|
25
|
+
// User Not Found
|
|
26
|
+
case 'auth/user-not-found':
|
|
27
|
+
return new exceptions_1.UserNotFoundException(error);
|
|
28
|
+
// Email Already In Use
|
|
31
29
|
case 'auth/email-already-in-use':
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
originalError: error
|
|
36
|
-
};
|
|
30
|
+
case 'auth/account-exists-with-different-credential':
|
|
31
|
+
return new exceptions_1.EmailAlreadyInUseException(error);
|
|
32
|
+
// Weak Password
|
|
37
33
|
case 'auth/weak-password':
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
return new exceptions_1.WeakPasswordException(error);
|
|
35
|
+
// Token Expired
|
|
36
|
+
case 'auth/id-token-expired':
|
|
37
|
+
case 'auth/user-token-expired':
|
|
38
|
+
case types_1.ProviderErrorCodes.USER_TOKEN_EXPIRED:
|
|
39
|
+
return new exceptions_1.TokenExpiredException(error);
|
|
40
|
+
// Network Error
|
|
43
41
|
case 'auth/network-request-failed':
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
message: 'Network error. Please check your connection.',
|
|
47
|
-
originalError: error
|
|
48
|
-
};
|
|
42
|
+
case 'auth/timeout':
|
|
43
|
+
return new exceptions_1.NetworkException(error);
|
|
49
44
|
// Google Sign-In Errors
|
|
45
|
+
case types_1.ProviderErrorCodes.GOOGLE_CANCELLED:
|
|
50
46
|
case 'auth/popup-closed-by-user':
|
|
51
47
|
case 'auth/cancelled-popup-request':
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
originalError: error
|
|
56
|
-
};
|
|
57
|
-
case 'auth/account-exists-with-different-credential':
|
|
58
|
-
return {
|
|
59
|
-
code: types_1.AuthErrorCode.EMAIL_ALREADY_IN_USE,
|
|
60
|
-
message: 'An account already exists with this email using a different sign-in method.',
|
|
61
|
-
originalError: error
|
|
62
|
-
};
|
|
63
|
-
case 'auth/invalid-credential':
|
|
64
|
-
return {
|
|
65
|
-
code: types_1.AuthErrorCode.INVALID_CREDENTIALS,
|
|
66
|
-
message: 'The credential received is invalid. Please try again.',
|
|
67
|
-
originalError: error
|
|
68
|
-
};
|
|
69
|
-
case 'auth/operation-not-allowed':
|
|
70
|
-
return {
|
|
71
|
-
code: types_1.AuthErrorCode.UNKNOWN,
|
|
72
|
-
message: 'This sign-in method is not enabled. Please contact support.',
|
|
73
|
-
originalError: error
|
|
74
|
-
};
|
|
75
|
-
case 'auth/user-disabled':
|
|
76
|
-
return {
|
|
77
|
-
code: types_1.AuthErrorCode.INVALID_CREDENTIALS,
|
|
78
|
-
message: 'This account has been disabled.',
|
|
79
|
-
originalError: error
|
|
80
|
-
};
|
|
48
|
+
return new exceptions_1.GoogleSignInCancelledException(error);
|
|
49
|
+
case types_1.ProviderErrorCodes.GOOGLE_PLAY_UNAVAILABLE:
|
|
50
|
+
return new exceptions_1.GooglePlayServicesUnavailableException(error);
|
|
81
51
|
// Apple Sign-In Errors
|
|
82
|
-
case
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// Token Expiration
|
|
90
|
-
case 'auth/id-token-expired':
|
|
91
|
-
case 'auth/user-token-expired':
|
|
92
|
-
return {
|
|
93
|
-
code: types_1.AuthErrorCode.TOKEN_EXPIRED,
|
|
94
|
-
message: 'Your session has expired. Please sign in again.',
|
|
95
|
-
originalError: error
|
|
96
|
-
};
|
|
97
|
-
// OAuth-Specific Errors
|
|
52
|
+
case types_1.ProviderErrorCodes.APPLE_CANCELLED:
|
|
53
|
+
return new exceptions_1.AppleSignInCancelledException(error);
|
|
54
|
+
case types_1.ProviderErrorCodes.APPLE_NOT_SUPPORTED:
|
|
55
|
+
return new exceptions_1.AppleSignInNotSupportedException(error);
|
|
56
|
+
// Configuration Errors
|
|
57
|
+
case 'auth/operation-not-allowed':
|
|
58
|
+
return new exceptions_1.ConfigurationException('This sign-in method is not enabled. Please check your Firebase configuration.', error);
|
|
98
59
|
case 'auth/unauthorized-domain':
|
|
99
|
-
return
|
|
100
|
-
code: types_1.AuthErrorCode.UNKNOWN,
|
|
101
|
-
message: 'This domain is not authorized for OAuth operations.',
|
|
102
|
-
originalError: error
|
|
103
|
-
};
|
|
60
|
+
return new exceptions_1.ConfigurationException('This domain is not authorized for OAuth operations.', error);
|
|
104
61
|
case 'auth/invalid-oauth-provider':
|
|
105
|
-
return {
|
|
106
|
-
code: types_1.AuthErrorCode.UNKNOWN,
|
|
107
|
-
message: 'The OAuth provider configuration is invalid.',
|
|
108
|
-
originalError: error
|
|
109
|
-
};
|
|
110
62
|
case 'auth/invalid-oauth-client-id':
|
|
111
|
-
return
|
|
112
|
-
|
|
113
|
-
message: 'The OAuth client ID is invalid.',
|
|
114
|
-
originalError: error
|
|
115
|
-
};
|
|
63
|
+
return new exceptions_1.ConfigurationException('The OAuth configuration is invalid.', error);
|
|
64
|
+
// Default
|
|
116
65
|
default:
|
|
117
|
-
return
|
|
118
|
-
code: types_1.AuthErrorCode.UNKNOWN,
|
|
119
|
-
message: fbError.message || 'An unknown error occurred.',
|
|
120
|
-
originalError: error
|
|
121
|
-
};
|
|
66
|
+
return new exceptions_1.UnknownAuthException(fbError.message || 'An unknown error occurred.', error);
|
|
122
67
|
}
|
|
123
68
|
};
|
|
124
69
|
exports.mapFirebaseError = mapFirebaseError;
|
|
70
|
+
/**
|
|
71
|
+
* Helper function to check if an error is a specific exception type
|
|
72
|
+
*/
|
|
73
|
+
const isAuthException = (error, exceptionType) => {
|
|
74
|
+
return error instanceof exceptionType;
|
|
75
|
+
};
|
|
76
|
+
exports.isAuthException = isAuthException;
|
|
77
|
+
/**
|
|
78
|
+
* Helper to extract user-friendly message from any error
|
|
79
|
+
*/
|
|
80
|
+
const getErrorMessage = (error) => {
|
|
81
|
+
if (error instanceof exceptions_1.AuthException) {
|
|
82
|
+
return error.message;
|
|
83
|
+
}
|
|
84
|
+
return error?.message || 'An unexpected error occurred';
|
|
85
|
+
};
|
|
86
|
+
exports.getErrorMessage = getErrorMessage;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export declare class AuthException extends Error {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
readonly originalError?: any;
|
|
4
|
+
readonly timestamp: Date;
|
|
5
|
+
constructor(message: string, code: string, originalError?: any);
|
|
6
|
+
toJSON(): {
|
|
7
|
+
name: string;
|
|
8
|
+
code: string;
|
|
9
|
+
message: string;
|
|
10
|
+
timestamp: string;
|
|
11
|
+
originalError: any;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export declare class InvalidCredentialsException extends AuthException {
|
|
15
|
+
constructor(originalError?: any);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Thrown when user account does not exist
|
|
19
|
+
*/
|
|
20
|
+
export declare class UserNotFoundException extends AuthException {
|
|
21
|
+
constructor(originalError?: any);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Thrown when attempting to sign up with an email that's already registered
|
|
25
|
+
*/
|
|
26
|
+
export declare class EmailAlreadyInUseException extends AuthException {
|
|
27
|
+
constructor(originalError?: any);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Thrown when password doesn't meet minimum security requirements
|
|
31
|
+
*/
|
|
32
|
+
export declare class WeakPasswordException extends AuthException {
|
|
33
|
+
constructor(originalError?: any);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Thrown when user's authentication token has expired
|
|
37
|
+
*/
|
|
38
|
+
export declare class TokenExpiredException extends AuthException {
|
|
39
|
+
constructor(originalError?: any);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Thrown when network connectivity issues occur
|
|
43
|
+
*/
|
|
44
|
+
export declare class NetworkException extends AuthException {
|
|
45
|
+
constructor(originalError?: any);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Thrown when Google Sign-In is cancelled by user
|
|
49
|
+
*/
|
|
50
|
+
export declare class GoogleSignInCancelledException extends AuthException {
|
|
51
|
+
constructor(originalError?: any);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Thrown when Apple Sign-In is cancelled by user
|
|
55
|
+
*/
|
|
56
|
+
export declare class AppleSignInCancelledException extends AuthException {
|
|
57
|
+
constructor(originalError?: any);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Thrown when Apple Sign-In is not supported on the device
|
|
61
|
+
*/
|
|
62
|
+
export declare class AppleSignInNotSupportedException extends AuthException {
|
|
63
|
+
constructor(originalError?: any);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Thrown when Google Play Services are not available
|
|
67
|
+
*/
|
|
68
|
+
export declare class GooglePlayServicesUnavailableException extends AuthException {
|
|
69
|
+
constructor(originalError?: any);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Thrown for configuration errors
|
|
73
|
+
*/
|
|
74
|
+
export declare class ConfigurationException extends AuthException {
|
|
75
|
+
constructor(message: string, originalError?: any);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Generic unknown error
|
|
79
|
+
*/
|
|
80
|
+
export declare class UnknownAuthException extends AuthException {
|
|
81
|
+
constructor(message?: string, originalError?: any);
|
|
82
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnknownAuthException = exports.ConfigurationException = exports.GooglePlayServicesUnavailableException = exports.AppleSignInNotSupportedException = exports.AppleSignInCancelledException = exports.GoogleSignInCancelledException = exports.NetworkException = exports.TokenExpiredException = exports.WeakPasswordException = exports.EmailAlreadyInUseException = exports.UserNotFoundException = exports.InvalidCredentialsException = exports.AuthException = void 0;
|
|
4
|
+
class AuthException extends Error {
|
|
5
|
+
code;
|
|
6
|
+
originalError;
|
|
7
|
+
timestamp;
|
|
8
|
+
constructor(message, code, originalError) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = this.constructor.name;
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.originalError = originalError;
|
|
13
|
+
this.timestamp = new Date();
|
|
14
|
+
if (Error.captureStackTrace) {
|
|
15
|
+
Error.captureStackTrace(this, this.constructor);
|
|
16
|
+
}
|
|
17
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
18
|
+
}
|
|
19
|
+
toJSON() {
|
|
20
|
+
return {
|
|
21
|
+
name: this.name,
|
|
22
|
+
code: this.code,
|
|
23
|
+
message: this.message,
|
|
24
|
+
timestamp: this.timestamp.toISOString(),
|
|
25
|
+
originalError: this.originalError?.code || this.originalError?.message,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.AuthException = AuthException;
|
|
30
|
+
class InvalidCredentialsException extends AuthException {
|
|
31
|
+
constructor(originalError) {
|
|
32
|
+
super('Invalid email or password. Please check your credentials and try again.', 'auth/invalid-credentials', originalError);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.InvalidCredentialsException = InvalidCredentialsException;
|
|
36
|
+
/**
|
|
37
|
+
* Thrown when user account does not exist
|
|
38
|
+
*/
|
|
39
|
+
class UserNotFoundException extends AuthException {
|
|
40
|
+
constructor(originalError) {
|
|
41
|
+
super('No account found with this email. Please sign up first.', 'auth/user-not-found', originalError);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.UserNotFoundException = UserNotFoundException;
|
|
45
|
+
/**
|
|
46
|
+
* Thrown when attempting to sign up with an email that's already registered
|
|
47
|
+
*/
|
|
48
|
+
class EmailAlreadyInUseException extends AuthException {
|
|
49
|
+
constructor(originalError) {
|
|
50
|
+
super('This email is already registered. Please sign in or use a different email.', 'auth/email-already-in-use', originalError);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.EmailAlreadyInUseException = EmailAlreadyInUseException;
|
|
54
|
+
/**
|
|
55
|
+
* Thrown when password doesn't meet minimum security requirements
|
|
56
|
+
*/
|
|
57
|
+
class WeakPasswordException extends AuthException {
|
|
58
|
+
constructor(originalError) {
|
|
59
|
+
super('Password is too weak. Please use at least 6 characters with a mix of letters and numbers.', 'auth/weak-password', originalError);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.WeakPasswordException = WeakPasswordException;
|
|
63
|
+
/**
|
|
64
|
+
* Thrown when user's authentication token has expired
|
|
65
|
+
*/
|
|
66
|
+
class TokenExpiredException extends AuthException {
|
|
67
|
+
constructor(originalError) {
|
|
68
|
+
super('Your session has expired. Please sign in again.', 'auth/token-expired', originalError);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.TokenExpiredException = TokenExpiredException;
|
|
72
|
+
/**
|
|
73
|
+
* Thrown when network connectivity issues occur
|
|
74
|
+
*/
|
|
75
|
+
class NetworkException extends AuthException {
|
|
76
|
+
constructor(originalError) {
|
|
77
|
+
super('Network error. Please check your internet connection and try again.', 'auth/network-error', originalError);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.NetworkException = NetworkException;
|
|
81
|
+
/**
|
|
82
|
+
* Thrown when Google Sign-In is cancelled by user
|
|
83
|
+
*/
|
|
84
|
+
class GoogleSignInCancelledException extends AuthException {
|
|
85
|
+
constructor(originalError) {
|
|
86
|
+
super('Google Sign-In was cancelled.', 'auth/google-sign-in-cancelled', originalError);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.GoogleSignInCancelledException = GoogleSignInCancelledException;
|
|
90
|
+
/**
|
|
91
|
+
* Thrown when Apple Sign-In is cancelled by user
|
|
92
|
+
*/
|
|
93
|
+
class AppleSignInCancelledException extends AuthException {
|
|
94
|
+
constructor(originalError) {
|
|
95
|
+
super('Apple Sign-In was cancelled.', 'auth/apple-sign-in-cancelled', originalError);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.AppleSignInCancelledException = AppleSignInCancelledException;
|
|
99
|
+
/**
|
|
100
|
+
* Thrown when Apple Sign-In is not supported on the device
|
|
101
|
+
*/
|
|
102
|
+
class AppleSignInNotSupportedException extends AuthException {
|
|
103
|
+
constructor(originalError) {
|
|
104
|
+
super('Apple Sign-In is only available on iOS 13+ devices.', 'auth/apple-sign-in-not-supported', originalError);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.AppleSignInNotSupportedException = AppleSignInNotSupportedException;
|
|
108
|
+
/**
|
|
109
|
+
* Thrown when Google Play Services are not available
|
|
110
|
+
*/
|
|
111
|
+
class GooglePlayServicesUnavailableException extends AuthException {
|
|
112
|
+
constructor(originalError) {
|
|
113
|
+
super('Google Play Services are not available. Please update Google Play Services.', 'auth/google-play-services-unavailable', originalError);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.GooglePlayServicesUnavailableException = GooglePlayServicesUnavailableException;
|
|
117
|
+
/**
|
|
118
|
+
* Thrown for configuration errors
|
|
119
|
+
*/
|
|
120
|
+
class ConfigurationException extends AuthException {
|
|
121
|
+
constructor(message, originalError) {
|
|
122
|
+
super(message, 'auth/configuration-error', originalError);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.ConfigurationException = ConfigurationException;
|
|
126
|
+
/**
|
|
127
|
+
* Generic unknown error
|
|
128
|
+
*/
|
|
129
|
+
class UnknownAuthException extends AuthException {
|
|
130
|
+
constructor(message = 'An unexpected error occurred.', originalError) {
|
|
131
|
+
super(message, 'auth/unknown', originalError);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.UnknownAuthException = UnknownAuthException;
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { AuthException, InvalidCredentialsException, UserNotFoundException, EmailAlreadyInUseException, WeakPasswordException, TokenExpiredException, NetworkException, GoogleSignInCancelledException, AppleSignInCancelledException, AppleSignInNotSupportedException, GooglePlayServicesUnavailableException, ConfigurationException, UnknownAuthException, } from './exceptions';
|
|
2
|
+
export { mapFirebaseError, isAuthException, getErrorMessage, } from './errorMapper';
|
package/dist/errors/index.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
3
|
+
exports.getErrorMessage = exports.isAuthException = exports.mapFirebaseError = exports.UnknownAuthException = exports.ConfigurationException = exports.GooglePlayServicesUnavailableException = exports.AppleSignInNotSupportedException = exports.AppleSignInCancelledException = exports.GoogleSignInCancelledException = exports.NetworkException = exports.TokenExpiredException = exports.WeakPasswordException = exports.EmailAlreadyInUseException = exports.UserNotFoundException = exports.InvalidCredentialsException = exports.AuthException = void 0;
|
|
4
|
+
var exceptions_1 = require("./exceptions");
|
|
5
|
+
Object.defineProperty(exports, "AuthException", { enumerable: true, get: function () { return exceptions_1.AuthException; } });
|
|
6
|
+
Object.defineProperty(exports, "InvalidCredentialsException", { enumerable: true, get: function () { return exceptions_1.InvalidCredentialsException; } });
|
|
7
|
+
Object.defineProperty(exports, "UserNotFoundException", { enumerable: true, get: function () { return exceptions_1.UserNotFoundException; } });
|
|
8
|
+
Object.defineProperty(exports, "EmailAlreadyInUseException", { enumerable: true, get: function () { return exceptions_1.EmailAlreadyInUseException; } });
|
|
9
|
+
Object.defineProperty(exports, "WeakPasswordException", { enumerable: true, get: function () { return exceptions_1.WeakPasswordException; } });
|
|
10
|
+
Object.defineProperty(exports, "TokenExpiredException", { enumerable: true, get: function () { return exceptions_1.TokenExpiredException; } });
|
|
11
|
+
Object.defineProperty(exports, "NetworkException", { enumerable: true, get: function () { return exceptions_1.NetworkException; } });
|
|
12
|
+
Object.defineProperty(exports, "GoogleSignInCancelledException", { enumerable: true, get: function () { return exceptions_1.GoogleSignInCancelledException; } });
|
|
13
|
+
Object.defineProperty(exports, "AppleSignInCancelledException", { enumerable: true, get: function () { return exceptions_1.AppleSignInCancelledException; } });
|
|
14
|
+
Object.defineProperty(exports, "AppleSignInNotSupportedException", { enumerable: true, get: function () { return exceptions_1.AppleSignInNotSupportedException; } });
|
|
15
|
+
Object.defineProperty(exports, "GooglePlayServicesUnavailableException", { enumerable: true, get: function () { return exceptions_1.GooglePlayServicesUnavailableException; } });
|
|
16
|
+
Object.defineProperty(exports, "ConfigurationException", { enumerable: true, get: function () { return exceptions_1.ConfigurationException; } });
|
|
17
|
+
Object.defineProperty(exports, "UnknownAuthException", { enumerable: true, get: function () { return exceptions_1.UnknownAuthException; } });
|
|
18
|
+
var errorMapper_1 = require("./errorMapper");
|
|
19
|
+
Object.defineProperty(exports, "mapFirebaseError", { enumerable: true, get: function () { return errorMapper_1.mapFirebaseError; } });
|
|
20
|
+
Object.defineProperty(exports, "isAuthException", { enumerable: true, get: function () { return errorMapper_1.isAuthException; } });
|
|
21
|
+
Object.defineProperty(exports, "getErrorMessage", { enumerable: true, get: function () { return errorMapper_1.getErrorMessage; } });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AuthConfig } from './config.types';
|
|
2
|
-
import {
|
|
2
|
+
import { AuthException } from '../errors';
|
|
3
3
|
export declare enum AuthStatus {
|
|
4
4
|
AUTHENTICATED = "AUTHENTICATED",
|
|
5
5
|
UNAUTHENTICATED = "UNAUTHENTICATED",
|
|
@@ -26,10 +26,11 @@ export interface AuthContextType {
|
|
|
26
26
|
user: User | null;
|
|
27
27
|
status: AuthStatus;
|
|
28
28
|
isLoading: boolean;
|
|
29
|
-
error:
|
|
29
|
+
error: AuthException | null;
|
|
30
30
|
config: AuthConfig;
|
|
31
31
|
signInWithEmail: (options: EmailSignInOptions) => Promise<void>;
|
|
32
32
|
signUpWithEmail: (options: EmailSignUpOptions) => Promise<void>;
|
|
33
|
+
sendPasswordReset: (email: string) => Promise<void>;
|
|
33
34
|
signInWithGoogle: () => Promise<void>;
|
|
34
35
|
signInWithApple: () => Promise<void>;
|
|
35
36
|
signOut: () => Promise<void>;
|
|
@@ -13,20 +13,21 @@ export declare enum AuthErrorCode {
|
|
|
13
13
|
EMAIL_ALREADY_IN_USE = "auth/email-already-in-use",
|
|
14
14
|
WEAK_PASSWORD = "auth/weak-password",
|
|
15
15
|
TOKEN_EXPIRED = "auth/token-expired",
|
|
16
|
-
NETWORK_ERROR = "auth/network-
|
|
16
|
+
NETWORK_ERROR = "auth/network-error",
|
|
17
17
|
UNKNOWN = "auth/unknown",
|
|
18
18
|
CONFIG_ERROR = "auth/configuration-error",
|
|
19
19
|
CANCELLED = "auth/cancelled",
|
|
20
|
-
GOOGLE_SIGN_IN_CANCELLED = "
|
|
21
|
-
GOOGLE_SIGN_IN_IN_PROGRESS = "
|
|
22
|
-
GOOGLE_PLAY_SERVICES_NOT_AVAILABLE = "
|
|
23
|
-
GOOGLE_SIGN_IN_FAILED = "
|
|
24
|
-
APPLE_SIGN_IN_CANCELLED = "
|
|
25
|
-
APPLE_SIGN_IN_FAILED = "
|
|
26
|
-
APPLE_SIGN_IN_NOT_SUPPORTED = "
|
|
20
|
+
GOOGLE_SIGN_IN_CANCELLED = "auth/google-sign-in-cancelled",
|
|
21
|
+
GOOGLE_SIGN_IN_IN_PROGRESS = "auth/google-sign-in-in-progress",
|
|
22
|
+
GOOGLE_PLAY_SERVICES_NOT_AVAILABLE = "auth/google-play-services-unavailable",
|
|
23
|
+
GOOGLE_SIGN_IN_FAILED = "auth/google-sign-in-failed",
|
|
24
|
+
APPLE_SIGN_IN_CANCELLED = "auth/apple-sign-in-cancelled",
|
|
25
|
+
APPLE_SIGN_IN_FAILED = "auth/apple-sign-in-failed",
|
|
26
|
+
APPLE_SIGN_IN_NOT_SUPPORTED = "auth/apple-sign-in-not-supported"
|
|
27
27
|
}
|
|
28
28
|
export interface AuthError {
|
|
29
29
|
code: string | ProviderErrorCodes | AuthErrorCode;
|
|
30
30
|
message: string;
|
|
31
31
|
originalError?: any;
|
|
32
32
|
}
|
|
33
|
+
export declare const isAuthError: (error: any) => error is AuthError;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// src/types/error.types.ts
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.AuthErrorCode = exports.ProviderErrorCodes = void 0;
|
|
5
|
-
// ✅ 1. Define Known Error Codes (Source of Truth)
|
|
3
|
+
exports.isAuthError = exports.AuthErrorCode = exports.ProviderErrorCodes = void 0;
|
|
6
4
|
var ProviderErrorCodes;
|
|
7
5
|
(function (ProviderErrorCodes) {
|
|
8
6
|
// Firebase specific
|
|
@@ -16,26 +14,35 @@ var ProviderErrorCodes;
|
|
|
16
14
|
ProviderErrorCodes["APPLE_CANCELLED"] = "ERR_REQUEST_CANCELED";
|
|
17
15
|
ProviderErrorCodes["APPLE_NOT_SUPPORTED"] = "APPLE_SIGN_IN_NOT_SUPPORTED";
|
|
18
16
|
})(ProviderErrorCodes || (exports.ProviderErrorCodes = ProviderErrorCodes = {}));
|
|
19
|
-
//
|
|
17
|
+
// ✅ Standardized error codes (used by custom exceptions)
|
|
20
18
|
var AuthErrorCode;
|
|
21
19
|
(function (AuthErrorCode) {
|
|
20
|
+
// Core authentication errors
|
|
22
21
|
AuthErrorCode["INVALID_CREDENTIALS"] = "auth/invalid-credentials";
|
|
23
22
|
AuthErrorCode["USER_NOT_FOUND"] = "auth/user-not-found";
|
|
24
23
|
AuthErrorCode["EMAIL_ALREADY_IN_USE"] = "auth/email-already-in-use";
|
|
25
24
|
AuthErrorCode["WEAK_PASSWORD"] = "auth/weak-password";
|
|
26
25
|
AuthErrorCode["TOKEN_EXPIRED"] = "auth/token-expired";
|
|
27
|
-
AuthErrorCode["NETWORK_ERROR"] = "auth/network-
|
|
26
|
+
AuthErrorCode["NETWORK_ERROR"] = "auth/network-error";
|
|
28
27
|
AuthErrorCode["UNKNOWN"] = "auth/unknown";
|
|
29
|
-
//
|
|
28
|
+
// Configuration errors
|
|
30
29
|
AuthErrorCode["CONFIG_ERROR"] = "auth/configuration-error";
|
|
30
|
+
// User actions
|
|
31
31
|
AuthErrorCode["CANCELLED"] = "auth/cancelled";
|
|
32
|
-
// Google Sign-In
|
|
33
|
-
AuthErrorCode["GOOGLE_SIGN_IN_CANCELLED"] = "
|
|
34
|
-
AuthErrorCode["GOOGLE_SIGN_IN_IN_PROGRESS"] = "
|
|
35
|
-
AuthErrorCode["GOOGLE_PLAY_SERVICES_NOT_AVAILABLE"] = "
|
|
36
|
-
AuthErrorCode["GOOGLE_SIGN_IN_FAILED"] = "
|
|
37
|
-
// Apple Sign-In
|
|
38
|
-
AuthErrorCode["APPLE_SIGN_IN_CANCELLED"] = "
|
|
39
|
-
AuthErrorCode["APPLE_SIGN_IN_FAILED"] = "
|
|
40
|
-
AuthErrorCode["APPLE_SIGN_IN_NOT_SUPPORTED"] = "
|
|
32
|
+
// Google Sign-In errors
|
|
33
|
+
AuthErrorCode["GOOGLE_SIGN_IN_CANCELLED"] = "auth/google-sign-in-cancelled";
|
|
34
|
+
AuthErrorCode["GOOGLE_SIGN_IN_IN_PROGRESS"] = "auth/google-sign-in-in-progress";
|
|
35
|
+
AuthErrorCode["GOOGLE_PLAY_SERVICES_NOT_AVAILABLE"] = "auth/google-play-services-unavailable";
|
|
36
|
+
AuthErrorCode["GOOGLE_SIGN_IN_FAILED"] = "auth/google-sign-in-failed";
|
|
37
|
+
// Apple Sign-In errors
|
|
38
|
+
AuthErrorCode["APPLE_SIGN_IN_CANCELLED"] = "auth/apple-sign-in-cancelled";
|
|
39
|
+
AuthErrorCode["APPLE_SIGN_IN_FAILED"] = "auth/apple-sign-in-failed";
|
|
40
|
+
AuthErrorCode["APPLE_SIGN_IN_NOT_SUPPORTED"] = "auth/apple-sign-in-not-supported";
|
|
41
41
|
})(AuthErrorCode || (exports.AuthErrorCode = AuthErrorCode = {}));
|
|
42
|
+
const isAuthError = (error) => {
|
|
43
|
+
return (error &&
|
|
44
|
+
typeof error === 'object' &&
|
|
45
|
+
'code' in error &&
|
|
46
|
+
'message' in error);
|
|
47
|
+
};
|
|
48
|
+
exports.isAuthError = isAuthError;
|