@umituz/react-native-firebase 2.6.2 → 2.6.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/package.json +1 -1
- package/src/application/auth/index.ts +2 -34
- package/src/application/auth/use-cases/index.ts +1 -21
- package/src/domains/account-deletion/domain/index.ts +1 -8
- package/src/domains/account-deletion/index.ts +0 -42
- package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor.ts +79 -0
- package/src/domains/account-deletion/infrastructure/services/AccountDeletionTypes.ts +0 -1
- package/src/domains/account-deletion/infrastructure/services/account-deletion.service.ts +2 -14
- package/src/domains/auth/index.ts +3 -12
- package/src/domains/auth/infrastructure.ts +11 -0
- package/src/domains/firestore/domain/entities/Collection.ts +0 -2
- package/src/domains/firestore/domain/index.ts +8 -12
- package/src/domains/firestore/domain/value-objects/{QueryOptions.ts.bak → QueryOptions.ts} +20 -68
- package/src/domains/firestore/domain/value-objects/QueryOptionsFactory.ts +95 -0
- package/src/domains/firestore/domain/value-objects/QueryOptionsHelpers.ts +110 -0
- package/src/domains/firestore/domain/value-objects/WhereClause.ts +115 -0
- package/src/domains/firestore/domain/value-objects/WhereClauseFactory.ts +101 -0
- package/src/domains/firestore/domain/value-objects/WhereClauseHelpers.ts +123 -0
- package/src/domains/firestore/domain/value-objects/WhereClauseValidation.ts +83 -0
- package/src/domains/firestore/presentation/hooks/useFirestoreMutation.ts +1 -1
- package/src/domains/firestore/presentation/hooks/useFirestoreQuery.ts +1 -1
- package/src/shared/infrastructure/config/base/ServiceClientSingleton.ts +29 -0
- package/src/application/auth/ports/AuthPort.ts.bak +0 -164
- package/src/application/auth/ports/AuthPort_part_aa +0 -150
- package/src/application/auth/ports/AuthPort_part_ab +0 -14
- package/src/application/auth/use-cases/SignInUseCase.ts.bak +0 -253
- package/src/application/auth/use-cases/SignInUseCaseHelpers.ts +0 -0
- package/src/application/auth/use-cases/SignInUseCaseMain.ts +0 -0
- package/src/application/auth/use-cases/SignInUseCase_part_aa +0 -150
- package/src/application/auth/use-cases/SignInUseCase_part_ab +0 -103
- package/src/application/auth/use-cases/SignOutUseCase.ts.bak +0 -288
- package/src/application/auth/use-cases/SignOutUseCaseCleanup.ts +0 -0
- package/src/application/auth/use-cases/SignOutUseCaseMain.ts +0 -0
- package/src/application/auth/use-cases/SignOutUseCase_part_aa +0 -150
- package/src/application/auth/use-cases/SignOutUseCase_part_ab +0 -138
- package/src/domains/account-deletion/domain/services/UserValidationHelpers.ts.bak +0 -181
- package/src/domains/account-deletion/domain/services/UserValidationHelpers_part_aa +0 -150
- package/src/domains/account-deletion/domain/services/UserValidationHelpers_part_ab +0 -31
- package/src/domains/account-deletion/domain/services/UserValidationService.ts.bak +0 -286
- package/src/domains/account-deletion/domain/services/UserValidationService_part_aa +0 -150
- package/src/domains/account-deletion/domain/services/UserValidationService_part_ab +0 -136
- package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor.ts.bak +0 -230
- package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor_part_aa +0 -150
- package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor_part_ab +0 -80
- package/src/domains/account-deletion/infrastructure/services/AccountDeletionReauthHandler.ts.bak +0 -174
- package/src/domains/account-deletion/infrastructure/services/AccountDeletionReauthHandler_part_aa +0 -150
- package/src/domains/account-deletion/infrastructure/services/AccountDeletionReauthHandler_part_ab +0 -24
- package/src/domains/account-deletion/infrastructure/services/AccountDeletionRepository.ts.bak +0 -266
- package/src/domains/account-deletion/infrastructure/services/AccountDeletionRepository_part_aa +0 -150
- package/src/domains/account-deletion/infrastructure/services/AccountDeletionRepository_part_ab +0 -116
- package/src/domains/account-deletion/infrastructure/services/reauthentication.service.ts.bak +0 -160
- package/src/domains/account-deletion/infrastructure/services/reauthentication.service_part_aa +0 -150
- package/src/domains/account-deletion/infrastructure/services/reauthentication.service_part_ab +0 -10
- package/src/domains/auth/infrastructure.ts.bak +0 -156
- package/src/domains/auth/infrastructure_part_aa +0 -150
- package/src/domains/auth/infrastructure_part_ab +0 -6
- package/src/domains/auth/presentation/hooks/GoogleOAuthHelpers.ts +0 -0
- package/src/domains/auth/presentation/hooks/GoogleOAuthHookService.ts.bak +0 -247
- package/src/domains/auth/presentation/hooks/GoogleOAuthHookService_part_aa +0 -150
- package/src/domains/auth/presentation/hooks/GoogleOAuthHookService_part_ab +0 -97
- package/src/domains/auth/presentation/hooks/GoogleOAuthService.ts +0 -0
- package/src/domains/firestore/domain/entities/Collection.ts.bak +0 -288
- package/src/domains/firestore/domain/entities/Collection_part_aa +0 -150
- package/src/domains/firestore/domain/entities/Collection_part_ab +0 -138
- package/src/domains/firestore/domain/entities/Document.ts.bak +0 -233
- package/src/domains/firestore/domain/entities/DocumentHelpers.ts +0 -0
- package/src/domains/firestore/domain/entities/DocumentMain.ts +0 -0
- package/src/domains/firestore/domain/entities/Document_part_aa +0 -150
- package/src/domains/firestore/domain/entities/Document_part_ab +0 -83
- package/src/domains/firestore/domain/services/QueryService.ts.bak +0 -182
- package/src/domains/firestore/domain/services/QueryServiceAnalysis.ts.bak +0 -169
- package/src/domains/firestore/domain/services/QueryServiceAnalysis_part_aa +0 -150
- package/src/domains/firestore/domain/services/QueryServiceAnalysis_part_ab +0 -19
- package/src/domains/firestore/domain/services/QueryServiceHelpers.ts.bak +0 -151
- package/src/domains/firestore/domain/services/QueryServiceHelpers_part_aa +0 -150
- package/src/domains/firestore/domain/services/QueryServiceHelpers_part_ab +0 -1
- package/src/domains/firestore/domain/services/QueryService_part_aa +0 -150
- package/src/domains/firestore/domain/services/QueryService_part_ab +0 -32
- package/src/domains/firestore/domain/value-objects/QueryOptionsSerialization.ts.bak +0 -207
- package/src/domains/firestore/domain/value-objects/QueryOptionsSerialization_part_aa +0 -150
- package/src/domains/firestore/domain/value-objects/QueryOptionsSerialization_part_ab +0 -57
- package/src/domains/firestore/domain/value-objects/QueryOptionsValidation.ts.bak +0 -182
- package/src/domains/firestore/domain/value-objects/QueryOptionsValidation_part_aa +0 -150
- package/src/domains/firestore/domain/value-objects/QueryOptionsValidation_part_ab +0 -32
- package/src/domains/firestore/domain/value-objects/QueryOptions_part_aa +0 -150
- package/src/domains/firestore/domain/value-objects/QueryOptions_part_ab +0 -41
- package/src/domains/firestore/domain/value-objects/WhereClause.ts.bak +0 -299
- package/src/domains/firestore/domain/value-objects/WhereClauseFactory.ts.bak +0 -207
- package/src/domains/firestore/domain/value-objects/WhereClauseFactory_part_aa +0 -150
- package/src/domains/firestore/domain/value-objects/WhereClauseFactory_part_ab +0 -57
- package/src/domains/firestore/domain/value-objects/WhereClause_part_aa +0 -150
- package/src/domains/firestore/domain/value-objects/WhereClause_part_ab +0 -149
- package/src/shared/infrastructure/base/ErrorHandler.ts.bak +0 -189
- package/src/shared/infrastructure/base/ErrorHandler_part_aa +0 -150
- package/src/shared/infrastructure/base/ErrorHandler_part_ab +0 -39
- package/src/shared/infrastructure/base/ServiceBase.ts.bak +0 -220
- package/src/shared/infrastructure/base/ServiceBase_part_aa +0 -150
- package/src/shared/infrastructure/base/ServiceBase_part_ab +0 -70
- package/src/shared/infrastructure/config/base/ServiceClientSingleton.ts.bak +0 -155
- package/src/shared/infrastructure/config/base/ServiceClientSingleton_part_aa +0 -150
- package/src/shared/infrastructure/config/base/ServiceClientSingleton_part_ab +0 -5
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Account Deletion Executor (Main)
|
|
3
|
-
* Single Responsibility: Execute account deletion with retry logic
|
|
4
|
-
*
|
|
5
|
-
* Infrastructure service that executes account deletion operations.
|
|
6
|
-
* Coordinates reauthentication and deletion with error handling.
|
|
7
|
-
*
|
|
8
|
-
* Max lines: 150 (enforced for maintainability)
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type { User } from 'firebase/auth';
|
|
12
|
-
import { getFirebaseAuth } from '../../../auth/infrastructure/config/FirebaseAuthClient';
|
|
13
|
-
import { AccountDeletionRepository } from './AccountDeletionRepository';
|
|
14
|
-
import { userValidationService } from '../../domain/services/UserValidationService';
|
|
15
|
-
import type { Result } from '../../../../shared/domain/utils';
|
|
16
|
-
import type { AccountDeletionOptions } from '../../application/ports/reauthentication.types';
|
|
17
|
-
import type { AccountDeletionResult } from './AccountDeletionTypes';
|
|
18
|
-
import { handleReauthentication } from './AccountDeletionReauthHandler';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Account deletion executor
|
|
22
|
-
* Executes account deletion with automatic reauthentication
|
|
23
|
-
*/
|
|
24
|
-
export class AccountDeletionExecutor {
|
|
25
|
-
private readonly repository: AccountDeletionRepository;
|
|
26
|
-
private deletionInProgress = false;
|
|
27
|
-
|
|
28
|
-
constructor(repository?: AccountDeletionRepository) {
|
|
29
|
-
this.repository = repository || new AccountDeletionRepository();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Delete current user account
|
|
34
|
-
* Handles reauthentication automatically if enabled
|
|
35
|
-
*/
|
|
36
|
-
async deleteCurrentUser(
|
|
37
|
-
options: AccountDeletionOptions = { autoReauthenticate: true }
|
|
38
|
-
): Promise<AccountDeletionResult> {
|
|
39
|
-
// Prevent concurrent deletion attempts
|
|
40
|
-
if (this.deletionInProgress) {
|
|
41
|
-
return {
|
|
42
|
-
success: false,
|
|
43
|
-
error: { code: 'auth/operation-in-progress', message: 'Account deletion already in progress' },
|
|
44
|
-
requiresReauth: false,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
this.deletionInProgress = true;
|
|
49
|
-
|
|
50
|
-
try {
|
|
51
|
-
const auth = getFirebaseAuth();
|
|
52
|
-
const user = auth?.currentUser;
|
|
53
|
-
|
|
54
|
-
if (!auth || !user) {
|
|
55
|
-
return {
|
|
56
|
-
success: false,
|
|
57
|
-
error: { code: 'auth/not-ready', message: 'Auth not ready' },
|
|
58
|
-
requiresReauth: false,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const originalUserId = user.uid;
|
|
63
|
-
|
|
64
|
-
// Validate user for deletion
|
|
65
|
-
const validation = await this.repository.validateForDeletion(user);
|
|
66
|
-
if (!validation.success) {
|
|
67
|
-
return {
|
|
68
|
-
success: false,
|
|
69
|
-
error: validation.error,
|
|
70
|
-
requiresReauth: false,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const provider = validation.data!.provider;
|
|
75
|
-
|
|
76
|
-
// Check if reauthentication is needed
|
|
77
|
-
const needsReauth = this.shouldReauthenticate(user, options, provider);
|
|
78
|
-
if (needsReauth) {
|
|
79
|
-
const reauthResult = await handleReauthentication(user, options, originalUserId, this.repository);
|
|
80
|
-
if (reauthResult) {
|
|
81
|
-
return reauthResult;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Attempt deletion
|
|
86
|
-
return await this.performDeletion(user, originalUserId, options);
|
|
87
|
-
} finally {
|
|
88
|
-
this.deletionInProgress = false;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Delete specific user account
|
|
94
|
-
* Direct deletion without reauthentication
|
|
95
|
-
*/
|
|
96
|
-
async deleteUserAccount(user: User | null): Promise<AccountDeletionResult> {
|
|
97
|
-
if (!user || user.isAnonymous) {
|
|
98
|
-
return {
|
|
99
|
-
success: false,
|
|
100
|
-
error: { code: 'auth/invalid', message: 'Invalid user' },
|
|
101
|
-
requiresReauth: false,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
const result = await this.repository.deleteAccount(user);
|
|
107
|
-
if (result.success) {
|
|
108
|
-
return { success: true };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
success: false,
|
|
113
|
-
error: result.error,
|
|
114
|
-
requiresReauth: result.error?.code === 'auth/requires-recent-login',
|
|
115
|
-
};
|
|
116
|
-
} catch (error: unknown) {
|
|
117
|
-
return {
|
|
118
|
-
success: false,
|
|
119
|
-
error: {
|
|
120
|
-
code: 'auth/failed',
|
|
121
|
-
message: error instanceof Error ? error.message : 'Unknown error',
|
|
122
|
-
},
|
|
123
|
-
requiresReauth: false,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Check if reauthentication is needed
|
|
130
|
-
*/
|
|
131
|
-
private shouldReauthenticate(
|
|
132
|
-
user: User,
|
|
133
|
-
options: AccountDeletionOptions,
|
|
134
|
-
provider: string
|
|
135
|
-
): boolean {
|
|
136
|
-
// Password users need reauthentication
|
|
137
|
-
if (provider === 'password' && options.autoReauthenticate && options.onPasswordRequired) {
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Check if credentials are provided
|
|
142
|
-
const hasCredentials = !!(options.password || options.googleIdToken);
|
|
143
|
-
if (hasCredentials) {
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Perform account deletion
|
|
152
|
-
*/
|
|
153
|
-
private async performDeletion(
|
|
154
|
-
user: User,
|
|
155
|
-
originalUserId: string,
|
|
156
|
-
options: AccountDeletionOptions
|
|
157
|
-
): Promise<AccountDeletionResult> {
|
|
158
|
-
try {
|
|
159
|
-
// Validate user hasn't changed
|
|
160
|
-
const auth = getFirebaseAuth();
|
|
161
|
-
const validation = userValidationService.validateUserUnchanged(auth, originalUserId);
|
|
162
|
-
if (!validation.success) {
|
|
163
|
-
return {
|
|
164
|
-
success: false,
|
|
165
|
-
error: validation.error!,
|
|
166
|
-
requiresReauth: false,
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Delete account
|
|
171
|
-
const result = await this.repository.deleteAccount(user);
|
|
172
|
-
if (result.success) {
|
|
173
|
-
return { success: true };
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Check if reauthentication can help
|
|
177
|
-
const error = result.error;
|
|
178
|
-
if (
|
|
179
|
-
error?.code === 'auth/requires-recent-login' &&
|
|
180
|
-
options.autoReauthenticate
|
|
181
|
-
) {
|
|
182
|
-
const reauthResult = await handleReauthentication(user, options, originalUserId, this.repository);
|
|
183
|
-
if (reauthResult) {
|
|
184
|
-
return reauthResult;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
return {
|
|
189
|
-
success: false,
|
|
190
|
-
error,
|
|
191
|
-
requiresReauth: error?.code === 'auth/requires-recent-login',
|
|
192
|
-
};
|
|
193
|
-
} catch (error: unknown) {
|
|
194
|
-
return {
|
|
195
|
-
success: false,
|
|
196
|
-
error: {
|
|
197
|
-
code: 'auth/failed',
|
|
198
|
-
message: error instanceof Error ? error.message : 'Unknown error',
|
|
199
|
-
},
|
|
200
|
-
requiresReauth: false,
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Check if deletion is in progress
|
|
207
|
-
*/
|
|
208
|
-
isDeletionInProgress(): boolean {
|
|
209
|
-
return this.deletionInProgress;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Get the repository instance
|
|
214
|
-
*/
|
|
215
|
-
getRepository(): AccountDeletionRepository {
|
|
216
|
-
return this.repository;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Factory function to create account deletion executor
|
|
222
|
-
*/
|
|
223
|
-
export function createAccountDeletionExecutor(): AccountDeletionExecutor {
|
|
224
|
-
return new AccountDeletionExecutor();
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Default singleton instance
|
|
229
|
-
*/
|
|
230
|
-
export const accountDeletionExecutor = createAccountDeletionExecutor();
|
package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor_part_aa
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Account Deletion Executor (Main)
|
|
3
|
-
* Single Responsibility: Execute account deletion with retry logic
|
|
4
|
-
*
|
|
5
|
-
* Infrastructure service that executes account deletion operations.
|
|
6
|
-
* Coordinates reauthentication and deletion with error handling.
|
|
7
|
-
*
|
|
8
|
-
* Max lines: 150 (enforced for maintainability)
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type { User } from 'firebase/auth';
|
|
12
|
-
import { getFirebaseAuth } from '../../../auth/infrastructure/config/FirebaseAuthClient';
|
|
13
|
-
import { AccountDeletionRepository } from './AccountDeletionRepository';
|
|
14
|
-
import { userValidationService } from '../../domain/services/UserValidationService';
|
|
15
|
-
import type { Result } from '../../../../shared/domain/utils';
|
|
16
|
-
import type { AccountDeletionOptions } from '../../application/ports/reauthentication.types';
|
|
17
|
-
import type { AccountDeletionResult } from './AccountDeletionTypes';
|
|
18
|
-
import { handleReauthentication } from './AccountDeletionReauthHandler';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Account deletion executor
|
|
22
|
-
* Executes account deletion with automatic reauthentication
|
|
23
|
-
*/
|
|
24
|
-
export class AccountDeletionExecutor {
|
|
25
|
-
private readonly repository: AccountDeletionRepository;
|
|
26
|
-
private deletionInProgress = false;
|
|
27
|
-
|
|
28
|
-
constructor(repository?: AccountDeletionRepository) {
|
|
29
|
-
this.repository = repository || new AccountDeletionRepository();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Delete current user account
|
|
34
|
-
* Handles reauthentication automatically if enabled
|
|
35
|
-
*/
|
|
36
|
-
async deleteCurrentUser(
|
|
37
|
-
options: AccountDeletionOptions = { autoReauthenticate: true }
|
|
38
|
-
): Promise<AccountDeletionResult> {
|
|
39
|
-
// Prevent concurrent deletion attempts
|
|
40
|
-
if (this.deletionInProgress) {
|
|
41
|
-
return {
|
|
42
|
-
success: false,
|
|
43
|
-
error: { code: 'auth/operation-in-progress', message: 'Account deletion already in progress' },
|
|
44
|
-
requiresReauth: false,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
this.deletionInProgress = true;
|
|
49
|
-
|
|
50
|
-
try {
|
|
51
|
-
const auth = getFirebaseAuth();
|
|
52
|
-
const user = auth?.currentUser;
|
|
53
|
-
|
|
54
|
-
if (!auth || !user) {
|
|
55
|
-
return {
|
|
56
|
-
success: false,
|
|
57
|
-
error: { code: 'auth/not-ready', message: 'Auth not ready' },
|
|
58
|
-
requiresReauth: false,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const originalUserId = user.uid;
|
|
63
|
-
|
|
64
|
-
// Validate user for deletion
|
|
65
|
-
const validation = await this.repository.validateForDeletion(user);
|
|
66
|
-
if (!validation.success) {
|
|
67
|
-
return {
|
|
68
|
-
success: false,
|
|
69
|
-
error: validation.error,
|
|
70
|
-
requiresReauth: false,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const provider = validation.data!.provider;
|
|
75
|
-
|
|
76
|
-
// Check if reauthentication is needed
|
|
77
|
-
const needsReauth = this.shouldReauthenticate(user, options, provider);
|
|
78
|
-
if (needsReauth) {
|
|
79
|
-
const reauthResult = await handleReauthentication(user, options, originalUserId, this.repository);
|
|
80
|
-
if (reauthResult) {
|
|
81
|
-
return reauthResult;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Attempt deletion
|
|
86
|
-
return await this.performDeletion(user, originalUserId, options);
|
|
87
|
-
} finally {
|
|
88
|
-
this.deletionInProgress = false;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Delete specific user account
|
|
94
|
-
* Direct deletion without reauthentication
|
|
95
|
-
*/
|
|
96
|
-
async deleteUserAccount(user: User | null): Promise<AccountDeletionResult> {
|
|
97
|
-
if (!user || user.isAnonymous) {
|
|
98
|
-
return {
|
|
99
|
-
success: false,
|
|
100
|
-
error: { code: 'auth/invalid', message: 'Invalid user' },
|
|
101
|
-
requiresReauth: false,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
const result = await this.repository.deleteAccount(user);
|
|
107
|
-
if (result.success) {
|
|
108
|
-
return { success: true };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
success: false,
|
|
113
|
-
error: result.error,
|
|
114
|
-
requiresReauth: result.error?.code === 'auth/requires-recent-login',
|
|
115
|
-
};
|
|
116
|
-
} catch (error: unknown) {
|
|
117
|
-
return {
|
|
118
|
-
success: false,
|
|
119
|
-
error: {
|
|
120
|
-
code: 'auth/failed',
|
|
121
|
-
message: error instanceof Error ? error.message : 'Unknown error',
|
|
122
|
-
},
|
|
123
|
-
requiresReauth: false,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Check if reauthentication is needed
|
|
130
|
-
*/
|
|
131
|
-
private shouldReauthenticate(
|
|
132
|
-
user: User,
|
|
133
|
-
options: AccountDeletionOptions,
|
|
134
|
-
provider: string
|
|
135
|
-
): boolean {
|
|
136
|
-
// Password users need reauthentication
|
|
137
|
-
if (provider === 'password' && options.autoReauthenticate && options.onPasswordRequired) {
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Check if credentials are provided
|
|
142
|
-
const hasCredentials = !!(options.password || options.googleIdToken);
|
|
143
|
-
if (hasCredentials) {
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor_part_ab
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
* Perform account deletion
|
|
2
|
-
*/
|
|
3
|
-
private async performDeletion(
|
|
4
|
-
user: User,
|
|
5
|
-
originalUserId: string,
|
|
6
|
-
options: AccountDeletionOptions
|
|
7
|
-
): Promise<AccountDeletionResult> {
|
|
8
|
-
try {
|
|
9
|
-
// Validate user hasn't changed
|
|
10
|
-
const auth = getFirebaseAuth();
|
|
11
|
-
const validation = userValidationService.validateUserUnchanged(auth, originalUserId);
|
|
12
|
-
if (!validation.success) {
|
|
13
|
-
return {
|
|
14
|
-
success: false,
|
|
15
|
-
error: validation.error!,
|
|
16
|
-
requiresReauth: false,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Delete account
|
|
21
|
-
const result = await this.repository.deleteAccount(user);
|
|
22
|
-
if (result.success) {
|
|
23
|
-
return { success: true };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Check if reauthentication can help
|
|
27
|
-
const error = result.error;
|
|
28
|
-
if (
|
|
29
|
-
error?.code === 'auth/requires-recent-login' &&
|
|
30
|
-
options.autoReauthenticate
|
|
31
|
-
) {
|
|
32
|
-
const reauthResult = await handleReauthentication(user, options, originalUserId, this.repository);
|
|
33
|
-
if (reauthResult) {
|
|
34
|
-
return reauthResult;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
success: false,
|
|
40
|
-
error,
|
|
41
|
-
requiresReauth: error?.code === 'auth/requires-recent-login',
|
|
42
|
-
};
|
|
43
|
-
} catch (error: unknown) {
|
|
44
|
-
return {
|
|
45
|
-
success: false,
|
|
46
|
-
error: {
|
|
47
|
-
code: 'auth/failed',
|
|
48
|
-
message: error instanceof Error ? error.message : 'Unknown error',
|
|
49
|
-
},
|
|
50
|
-
requiresReauth: false,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Check if deletion is in progress
|
|
57
|
-
*/
|
|
58
|
-
isDeletionInProgress(): boolean {
|
|
59
|
-
return this.deletionInProgress;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Get the repository instance
|
|
64
|
-
*/
|
|
65
|
-
getRepository(): AccountDeletionRepository {
|
|
66
|
-
return this.repository;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Factory function to create account deletion executor
|
|
72
|
-
*/
|
|
73
|
-
export function createAccountDeletionExecutor(): AccountDeletionExecutor {
|
|
74
|
-
return new AccountDeletionExecutor();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Default singleton instance
|
|
79
|
-
*/
|
|
80
|
-
export const accountDeletionExecutor = createAccountDeletionExecutor();
|
package/src/domains/account-deletion/infrastructure/services/AccountDeletionReauthHandler.ts.bak
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Account Deletion Reauthentication Handler
|
|
3
|
-
* Single Responsibility: Handle reauthentication during account deletion
|
|
4
|
-
*
|
|
5
|
-
* Max lines: 150 (enforced for maintainability)
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { User } from 'firebase/auth';
|
|
9
|
-
import { getFirebaseAuth } from '../../../auth/infrastructure/config/FirebaseAuthClient';
|
|
10
|
-
import { userValidationService } from '../../domain/services/UserValidationService';
|
|
11
|
-
import type { Result } from '../../../../shared/domain/utils';
|
|
12
|
-
import type { AccountDeletionOptions } from '../../application/ports/reauthentication.types';
|
|
13
|
-
import type { AccountDeletionResult, ReauthenticationContext } from './AccountDeletionTypes';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Handle reauthentication during account deletion
|
|
17
|
-
* Coordinates reauthentication flow with credential management
|
|
18
|
-
*/
|
|
19
|
-
export async function handleReauthentication(
|
|
20
|
-
user: User,
|
|
21
|
-
options: AccountDeletionOptions,
|
|
22
|
-
originalUserId: string | undefined,
|
|
23
|
-
repository: any
|
|
24
|
-
): Promise<AccountDeletionResult | null> {
|
|
25
|
-
// Validate user hasn't changed before reauthentication
|
|
26
|
-
if (originalUserId) {
|
|
27
|
-
const auth = getFirebaseAuth();
|
|
28
|
-
const validation = userValidationService.validateUserUnchanged(auth, originalUserId);
|
|
29
|
-
if (!validation.success) {
|
|
30
|
-
return {
|
|
31
|
-
success: false,
|
|
32
|
-
error: validation.error!,
|
|
33
|
-
requiresReauth: false,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Import reauthentication functions
|
|
39
|
-
const {
|
|
40
|
-
getUserAuthProvider,
|
|
41
|
-
reauthenticateWithApple,
|
|
42
|
-
reauthenticateWithPassword,
|
|
43
|
-
reauthenticateWithGoogle,
|
|
44
|
-
} = await import('./reauthentication.service');
|
|
45
|
-
|
|
46
|
-
const provider = getUserAuthProvider(user);
|
|
47
|
-
|
|
48
|
-
// Attempt reauthentication based on provider
|
|
49
|
-
let reauthResult: { success: boolean; error?: { code?: string; message?: string } } | null = null;
|
|
50
|
-
|
|
51
|
-
if (provider === 'apple.com') {
|
|
52
|
-
reauthResult = await reauthenticateWithApple(user);
|
|
53
|
-
} else if (provider === 'google.com') {
|
|
54
|
-
const googleToken = await getGoogleToken(options);
|
|
55
|
-
if (!googleToken) {
|
|
56
|
-
return {
|
|
57
|
-
success: false,
|
|
58
|
-
error: { code: 'auth/google-reauth', message: 'Google reauthentication required' },
|
|
59
|
-
requiresReauth: true,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
reauthResult = await reauthenticateWithGoogle(user, googleToken);
|
|
63
|
-
} else if (provider === 'password') {
|
|
64
|
-
const password = await getPassword(options);
|
|
65
|
-
if (!password) {
|
|
66
|
-
return {
|
|
67
|
-
success: false,
|
|
68
|
-
error: { code: 'auth/password-reauth', message: 'Password required' },
|
|
69
|
-
requiresReauth: true,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
reauthResult = await reauthenticateWithPassword(user, password);
|
|
73
|
-
} else {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// If reauthentication successful, retry deletion
|
|
78
|
-
if (reauthResult.success) {
|
|
79
|
-
return await retryDeletionAfterReauth(originalUserId, repository);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
success: false,
|
|
84
|
-
error: {
|
|
85
|
-
code: reauthResult.error?.code || 'auth/reauth-failed',
|
|
86
|
-
message: reauthResult.error?.message || 'Reauthentication failed',
|
|
87
|
-
},
|
|
88
|
-
requiresReauth: true,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Get Google ID token from options or callback
|
|
94
|
-
*/
|
|
95
|
-
async function getGoogleToken(options: AccountDeletionOptions): Promise<string | undefined> {
|
|
96
|
-
if (options.googleIdToken) {
|
|
97
|
-
return options.googleIdToken;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (options.onGoogleReauthRequired) {
|
|
101
|
-
return await options.onGoogleReauthRequired();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return undefined;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Get password from options or callback
|
|
109
|
-
*/
|
|
110
|
-
async function getPassword(options: AccountDeletionOptions): Promise<string | undefined> {
|
|
111
|
-
if (options.password) {
|
|
112
|
-
return options.password;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (options.onPasswordRequired) {
|
|
116
|
-
return await options.onPasswordRequired();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return undefined;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Retry deletion after successful reauthentication
|
|
124
|
-
*/
|
|
125
|
-
async function retryDeletionAfterReauth(
|
|
126
|
-
originalUserId: string | undefined,
|
|
127
|
-
repository: any
|
|
128
|
-
): Promise<AccountDeletionResult> {
|
|
129
|
-
try {
|
|
130
|
-
const auth = getFirebaseAuth();
|
|
131
|
-
const user = auth?.currentUser;
|
|
132
|
-
|
|
133
|
-
if (!user) {
|
|
134
|
-
return {
|
|
135
|
-
success: false,
|
|
136
|
-
error: { code: 'auth/not-ready', message: 'User not found after reauthentication' },
|
|
137
|
-
requiresReauth: false,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Validate user hasn't changed after reauthentication
|
|
142
|
-
if (originalUserId) {
|
|
143
|
-
const validation = userValidationService.validateUserUnchanged(auth, originalUserId);
|
|
144
|
-
if (!validation.success) {
|
|
145
|
-
return {
|
|
146
|
-
success: false,
|
|
147
|
-
error: validation.error!,
|
|
148
|
-
requiresReauth: false,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Delete account
|
|
154
|
-
const result = await repository.deleteAccount(user);
|
|
155
|
-
if (result.success) {
|
|
156
|
-
return { success: true };
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return {
|
|
160
|
-
success: false,
|
|
161
|
-
error: result.error,
|
|
162
|
-
requiresReauth: false,
|
|
163
|
-
};
|
|
164
|
-
} catch (error: unknown) {
|
|
165
|
-
return {
|
|
166
|
-
success: false,
|
|
167
|
-
error: {
|
|
168
|
-
code: 'auth/failed',
|
|
169
|
-
message: error instanceof Error ? error.message : 'Unknown error',
|
|
170
|
-
},
|
|
171
|
-
requiresReauth: false,
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
}
|