@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,247 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Google OAuth Hook Service
|
|
3
|
-
* Single Responsibility: Handle Google OAuth business logic
|
|
4
|
-
*
|
|
5
|
-
* Service class that manages Google OAuth flow.
|
|
6
|
-
* Separates business logic from React hook concerns.
|
|
7
|
-
*
|
|
8
|
-
* Max lines: 150 (enforced for maintainability)
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type { Auth } from 'firebase/auth';
|
|
12
|
-
import { googleOAuthService } from '../../infrastructure/services/google-oauth.service';
|
|
13
|
-
import type { GoogleOAuthConfig } from '../../infrastructure/services/google-oauth.service';
|
|
14
|
-
|
|
15
|
-
// Conditional import for expo-auth-session
|
|
16
|
-
interface AuthSessionResponse {
|
|
17
|
-
type: string;
|
|
18
|
-
authentication?: { idToken?: string } | null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
interface ExpoAuthSessionModule {
|
|
22
|
-
useAuthRequest: (config: {
|
|
23
|
-
iosClientId: string;
|
|
24
|
-
webClientId: string;
|
|
25
|
-
androidClientId: string;
|
|
26
|
-
}) => [unknown, AuthSessionResponse | null, (() => Promise<AuthSessionResponse>) | null];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let ExpoAuthSession: ExpoAuthSessionModule | null = null;
|
|
30
|
-
let isExpoAuthAvailable = false;
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
34
|
-
ExpoAuthSession = require('expo-auth-session/providers/google') as ExpoAuthSessionModule;
|
|
35
|
-
isExpoAuthAvailable = true;
|
|
36
|
-
} catch {
|
|
37
|
-
// expo-auth-session not available
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Google OAuth hook service
|
|
42
|
-
* Manages OAuth flow, response handling, and errors
|
|
43
|
-
*/
|
|
44
|
-
export class GoogleOAuthHookService {
|
|
45
|
-
private config: GoogleOAuthConfig | undefined;
|
|
46
|
-
private authRequest: [unknown, AuthSessionResponse | null, (() => Promise<AuthSessionResponse>) | null];
|
|
47
|
-
|
|
48
|
-
constructor(config?: GoogleOAuthConfig) {
|
|
49
|
-
this.config = config;
|
|
50
|
-
this.authRequest = this.initAuthRequest();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Initialize auth request
|
|
55
|
-
* Uses expo-auth-session if available
|
|
56
|
-
*/
|
|
57
|
-
private initAuthRequest(): [unknown, AuthSessionResponse | null, (() => Promise<AuthSessionResponse>) | null] {
|
|
58
|
-
if (!isExpoAuthAvailable || !ExpoAuthSession) {
|
|
59
|
-
return [null, null, null];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return ExpoAuthSession.useAuthRequest({
|
|
63
|
-
iosClientId: this.config?.iosClientId ?? '',
|
|
64
|
-
webClientId: this.config?.webClientId ?? '',
|
|
65
|
-
androidClientId: this.config?.androidClientId ?? '',
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Check if Google OAuth is available
|
|
71
|
-
*/
|
|
72
|
-
isAvailable(): boolean {
|
|
73
|
-
return isExpoAuthAvailable;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Check if Google OAuth is configured
|
|
78
|
-
*/
|
|
79
|
-
isConfigured(): boolean {
|
|
80
|
-
return googleOAuthService.isConfigured(this.config);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Update configuration
|
|
85
|
-
*/
|
|
86
|
-
updateConfig(config: GoogleOAuthConfig | undefined): void {
|
|
87
|
-
this.config = config;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Get auth request tuple
|
|
92
|
-
*/
|
|
93
|
-
getAuthRequest(): [unknown, AuthSessionResponse | null, (() => Promise<AuthSessionResponse>) | null] {
|
|
94
|
-
return this.authRequest;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Handle OAuth response
|
|
99
|
-
* Called when expo-auth-session returns a response
|
|
100
|
-
*/
|
|
101
|
-
async handleResponse(response: AuthSessionResponse | null, auth: Auth | null): Promise<void> {
|
|
102
|
-
if (!response) return;
|
|
103
|
-
|
|
104
|
-
if (response.type === 'success' && response.authentication?.idToken) {
|
|
105
|
-
if (!auth) {
|
|
106
|
-
throw new Error('Firebase Auth not initialized');
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
await googleOAuthService.signInWithOAuth(
|
|
110
|
-
auth,
|
|
111
|
-
this.config,
|
|
112
|
-
async () => response
|
|
113
|
-
);
|
|
114
|
-
} else if (response.type === 'error') {
|
|
115
|
-
throw new Error('Google authentication failed');
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Sign in with Google
|
|
121
|
-
* Initiates OAuth flow and returns result
|
|
122
|
-
*/
|
|
123
|
-
async signIn(auth: Auth | null): Promise<{ success: boolean; isNewUser?: boolean; error?: string }> {
|
|
124
|
-
if (!this.isAvailable()) {
|
|
125
|
-
const error = 'expo-auth-session is not available. Please install expo-auth-session and expo-web-browser.';
|
|
126
|
-
throw new Error(error);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (!this.isConfigured()) {
|
|
130
|
-
const error = 'Google Sign-In is not configured. Please provide valid client IDs.';
|
|
131
|
-
throw new Error(error);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const [, , promptAsync] = this.authRequest;
|
|
135
|
-
|
|
136
|
-
if (!promptAsync) {
|
|
137
|
-
throw new Error('Google Sign-In not ready');
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (!auth) {
|
|
141
|
-
throw new Error('Firebase Auth not initialized');
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return await googleOAuthService.signInWithOAuth(auth, this.config, promptAsync);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Validate OAuth state
|
|
149
|
-
*/
|
|
150
|
-
validate(): { valid: boolean; error?: string } {
|
|
151
|
-
if (!this.isAvailable()) {
|
|
152
|
-
return {
|
|
153
|
-
valid: false,
|
|
154
|
-
error: 'expo-auth-session is not available. Please install expo-auth-session and expo-web-browser.',
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (!this.isConfigured()) {
|
|
159
|
-
return {
|
|
160
|
-
valid: false,
|
|
161
|
-
error: 'Google Sign-In is not configured. Please provide valid client IDs.',
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return { valid: true };
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Get error message from error
|
|
170
|
-
*/
|
|
171
|
-
getErrorMessage(error: unknown): string {
|
|
172
|
-
if (error instanceof Error) {
|
|
173
|
-
return error.message;
|
|
174
|
-
}
|
|
175
|
-
return 'Google sign-in failed';
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Check if response is successful
|
|
180
|
-
*/
|
|
181
|
-
isSuccessfulResponse(response: AuthSessionResponse | null): boolean {
|
|
182
|
-
return response?.type === 'success' && !!response.authentication?.idToken;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Check if response is error
|
|
187
|
-
*/
|
|
188
|
-
isErrorResponse(response: AuthSessionResponse | null): boolean {
|
|
189
|
-
return response?.type === 'error';
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Extract ID token from response
|
|
194
|
-
*/
|
|
195
|
-
extractIdToken(response: AuthSessionResponse | null): string | null {
|
|
196
|
-
return response?.authentication?.idToken || null;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Create error result
|
|
201
|
-
*/
|
|
202
|
-
createErrorResult(error: string): { success: false; error: string } {
|
|
203
|
-
return { success: false, error };
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Check if auth request is ready
|
|
208
|
-
*/
|
|
209
|
-
isReady(): boolean {
|
|
210
|
-
const [request, , promptAsync] = this.authRequest;
|
|
211
|
-
return request !== null && promptAsync !== null;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Get configuration
|
|
216
|
-
*/
|
|
217
|
-
getConfig(): GoogleOAuthConfig | undefined {
|
|
218
|
-
return this.config;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Reset service state
|
|
223
|
-
*/
|
|
224
|
-
reset(): void {
|
|
225
|
-
this.config = undefined;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Factory function to create Google OAuth hook service
|
|
231
|
-
*/
|
|
232
|
-
export function createGoogleOAuthHookService(config?: GoogleOAuthConfig): GoogleOAuthHookService {
|
|
233
|
-
return new GoogleOAuthHookService(config);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Check if expo-auth-session is available
|
|
238
|
-
* Useful for conditional rendering
|
|
239
|
-
*/
|
|
240
|
-
export function isExpoAuthSessionAvailable(): boolean {
|
|
241
|
-
return isExpoAuthAvailable;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Re-export types for convenience
|
|
246
|
-
*/
|
|
247
|
-
export type { AuthSessionResponse, ExpoAuthSessionModule };
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Google OAuth Hook Service
|
|
3
|
-
* Single Responsibility: Handle Google OAuth business logic
|
|
4
|
-
*
|
|
5
|
-
* Service class that manages Google OAuth flow.
|
|
6
|
-
* Separates business logic from React hook concerns.
|
|
7
|
-
*
|
|
8
|
-
* Max lines: 150 (enforced for maintainability)
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type { Auth } from 'firebase/auth';
|
|
12
|
-
import { googleOAuthService } from '../../infrastructure/services/google-oauth.service';
|
|
13
|
-
import type { GoogleOAuthConfig } from '../../infrastructure/services/google-oauth.service';
|
|
14
|
-
|
|
15
|
-
// Conditional import for expo-auth-session
|
|
16
|
-
interface AuthSessionResponse {
|
|
17
|
-
type: string;
|
|
18
|
-
authentication?: { idToken?: string } | null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
interface ExpoAuthSessionModule {
|
|
22
|
-
useAuthRequest: (config: {
|
|
23
|
-
iosClientId: string;
|
|
24
|
-
webClientId: string;
|
|
25
|
-
androidClientId: string;
|
|
26
|
-
}) => [unknown, AuthSessionResponse | null, (() => Promise<AuthSessionResponse>) | null];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let ExpoAuthSession: ExpoAuthSessionModule | null = null;
|
|
30
|
-
let isExpoAuthAvailable = false;
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
34
|
-
ExpoAuthSession = require('expo-auth-session/providers/google') as ExpoAuthSessionModule;
|
|
35
|
-
isExpoAuthAvailable = true;
|
|
36
|
-
} catch {
|
|
37
|
-
// expo-auth-session not available
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Google OAuth hook service
|
|
42
|
-
* Manages OAuth flow, response handling, and errors
|
|
43
|
-
*/
|
|
44
|
-
export class GoogleOAuthHookService {
|
|
45
|
-
private config: GoogleOAuthConfig | undefined;
|
|
46
|
-
private authRequest: [unknown, AuthSessionResponse | null, (() => Promise<AuthSessionResponse>) | null];
|
|
47
|
-
|
|
48
|
-
constructor(config?: GoogleOAuthConfig) {
|
|
49
|
-
this.config = config;
|
|
50
|
-
this.authRequest = this.initAuthRequest();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Initialize auth request
|
|
55
|
-
* Uses expo-auth-session if available
|
|
56
|
-
*/
|
|
57
|
-
private initAuthRequest(): [unknown, AuthSessionResponse | null, (() => Promise<AuthSessionResponse>) | null] {
|
|
58
|
-
if (!isExpoAuthAvailable || !ExpoAuthSession) {
|
|
59
|
-
return [null, null, null];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return ExpoAuthSession.useAuthRequest({
|
|
63
|
-
iosClientId: this.config?.iosClientId ?? '',
|
|
64
|
-
webClientId: this.config?.webClientId ?? '',
|
|
65
|
-
androidClientId: this.config?.androidClientId ?? '',
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Check if Google OAuth is available
|
|
71
|
-
*/
|
|
72
|
-
isAvailable(): boolean {
|
|
73
|
-
return isExpoAuthAvailable;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Check if Google OAuth is configured
|
|
78
|
-
*/
|
|
79
|
-
isConfigured(): boolean {
|
|
80
|
-
return googleOAuthService.isConfigured(this.config);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Update configuration
|
|
85
|
-
*/
|
|
86
|
-
updateConfig(config: GoogleOAuthConfig | undefined): void {
|
|
87
|
-
this.config = config;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Get auth request tuple
|
|
92
|
-
*/
|
|
93
|
-
getAuthRequest(): [unknown, AuthSessionResponse | null, (() => Promise<AuthSessionResponse>) | null] {
|
|
94
|
-
return this.authRequest;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Handle OAuth response
|
|
99
|
-
* Called when expo-auth-session returns a response
|
|
100
|
-
*/
|
|
101
|
-
async handleResponse(response: AuthSessionResponse | null, auth: Auth | null): Promise<void> {
|
|
102
|
-
if (!response) return;
|
|
103
|
-
|
|
104
|
-
if (response.type === 'success' && response.authentication?.idToken) {
|
|
105
|
-
if (!auth) {
|
|
106
|
-
throw new Error('Firebase Auth not initialized');
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
await googleOAuthService.signInWithOAuth(
|
|
110
|
-
auth,
|
|
111
|
-
this.config,
|
|
112
|
-
async () => response
|
|
113
|
-
);
|
|
114
|
-
} else if (response.type === 'error') {
|
|
115
|
-
throw new Error('Google authentication failed');
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Sign in with Google
|
|
121
|
-
* Initiates OAuth flow and returns result
|
|
122
|
-
*/
|
|
123
|
-
async signIn(auth: Auth | null): Promise<{ success: boolean; isNewUser?: boolean; error?: string }> {
|
|
124
|
-
if (!this.isAvailable()) {
|
|
125
|
-
const error = 'expo-auth-session is not available. Please install expo-auth-session and expo-web-browser.';
|
|
126
|
-
throw new Error(error);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (!this.isConfigured()) {
|
|
130
|
-
const error = 'Google Sign-In is not configured. Please provide valid client IDs.';
|
|
131
|
-
throw new Error(error);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const [, , promptAsync] = this.authRequest;
|
|
135
|
-
|
|
136
|
-
if (!promptAsync) {
|
|
137
|
-
throw new Error('Google Sign-In not ready');
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (!auth) {
|
|
141
|
-
throw new Error('Firebase Auth not initialized');
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return await googleOAuthService.signInWithOAuth(auth, this.config, promptAsync);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Validate OAuth state
|
|
149
|
-
*/
|
|
150
|
-
validate(): { valid: boolean; error?: string } {
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
if (!this.isAvailable()) {
|
|
2
|
-
return {
|
|
3
|
-
valid: false,
|
|
4
|
-
error: 'expo-auth-session is not available. Please install expo-auth-session and expo-web-browser.',
|
|
5
|
-
};
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (!this.isConfigured()) {
|
|
9
|
-
return {
|
|
10
|
-
valid: false,
|
|
11
|
-
error: 'Google Sign-In is not configured. Please provide valid client IDs.',
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return { valid: true };
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Get error message from error
|
|
20
|
-
*/
|
|
21
|
-
getErrorMessage(error: unknown): string {
|
|
22
|
-
if (error instanceof Error) {
|
|
23
|
-
return error.message;
|
|
24
|
-
}
|
|
25
|
-
return 'Google sign-in failed';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Check if response is successful
|
|
30
|
-
*/
|
|
31
|
-
isSuccessfulResponse(response: AuthSessionResponse | null): boolean {
|
|
32
|
-
return response?.type === 'success' && !!response.authentication?.idToken;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Check if response is error
|
|
37
|
-
*/
|
|
38
|
-
isErrorResponse(response: AuthSessionResponse | null): boolean {
|
|
39
|
-
return response?.type === 'error';
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Extract ID token from response
|
|
44
|
-
*/
|
|
45
|
-
extractIdToken(response: AuthSessionResponse | null): string | null {
|
|
46
|
-
return response?.authentication?.idToken || null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Create error result
|
|
51
|
-
*/
|
|
52
|
-
createErrorResult(error: string): { success: false; error: string } {
|
|
53
|
-
return { success: false, error };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Check if auth request is ready
|
|
58
|
-
*/
|
|
59
|
-
isReady(): boolean {
|
|
60
|
-
const [request, , promptAsync] = this.authRequest;
|
|
61
|
-
return request !== null && promptAsync !== null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Get configuration
|
|
66
|
-
*/
|
|
67
|
-
getConfig(): GoogleOAuthConfig | undefined {
|
|
68
|
-
return this.config;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Reset service state
|
|
73
|
-
*/
|
|
74
|
-
reset(): void {
|
|
75
|
-
this.config = undefined;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Factory function to create Google OAuth hook service
|
|
81
|
-
*/
|
|
82
|
-
export function createGoogleOAuthHookService(config?: GoogleOAuthConfig): GoogleOAuthHookService {
|
|
83
|
-
return new GoogleOAuthHookService(config);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Check if expo-auth-session is available
|
|
88
|
-
* Useful for conditional rendering
|
|
89
|
-
*/
|
|
90
|
-
export function isExpoAuthSessionAvailable(): boolean {
|
|
91
|
-
return isExpoAuthAvailable;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Re-export types for convenience
|
|
96
|
-
*/
|
|
97
|
-
export type { AuthSessionResponse, ExpoAuthSessionModule };
|
|
File without changes
|