@umituz/react-native-auth 3.7.1 → 3.8.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-auth",
3
- "version": "3.7.1",
3
+ "version": "3.8.0",
4
4
  "description": "Authentication service for React Native apps - Secure, type-safe, and production-ready. Provider-agnostic design with dependency injection, configurable validation, and comprehensive error handling.",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -36,8 +36,6 @@
36
36
  "@react-navigation/stack": ">=6.0.0",
37
37
  "@tanstack/react-query": ">=5.0.0",
38
38
  "expo": ">=54.0.0",
39
- "expo-auth-session": ">=5.0.0",
40
- "expo-web-browser": ">=12.0.0",
41
39
  "firebase": ">=11.0.0",
42
40
  "react": ">=19.0.0",
43
41
  "react-native": "0.81.4",
package/src/index.ts CHANGED
@@ -57,8 +57,6 @@ export { useProfileEdit } from './presentation/hooks/useProfileEdit';
57
57
  export type { ProfileEditFormState, UseProfileEditReturn } from './presentation/hooks/useProfileEdit';
58
58
  export { useSocialLogin } from './presentation/hooks/useSocialLogin';
59
59
  export type { UseSocialLoginConfig, UseSocialLoginResult } from './presentation/hooks/useSocialLogin';
60
- export { useGoogleAuth } from './presentation/hooks/useGoogleAuth';
61
- export type { UseGoogleAuthResult } from './presentation/hooks/useGoogleAuth';
62
60
  export { useAppleAuth } from './presentation/hooks/useAppleAuth';
63
61
  export type { UseAppleAuthResult } from './presentation/hooks/useAppleAuth';
64
62
  export { useAuthBottomSheet } from './presentation/hooks/useAuthBottomSheet';
@@ -1,125 +0,0 @@
1
- /**
2
- * useGoogleAuth Hook
3
- * Handles Google OAuth flow using expo-auth-session and Firebase auth
4
- */
5
-
6
- import { useState, useCallback, useEffect } from "react";
7
- import { useSocialAuth, type SocialAuthConfig, type SocialAuthResult } from "@umituz/react-native-firebase";
8
- import * as Google from "expo-auth-session/providers/google";
9
- import * as WebBrowser from "expo-web-browser";
10
-
11
- WebBrowser.maybeCompleteAuthSession();
12
-
13
- export interface GoogleAuthConfig {
14
- iosClientId?: string;
15
- webClientId?: string;
16
- androidClientId?: string;
17
- }
18
-
19
- export interface UseGoogleAuthResult {
20
- signInWithGoogle: () => Promise<SocialAuthResult>;
21
- googleLoading: boolean;
22
- googleConfigured: boolean;
23
- googleError: string | null;
24
- }
25
-
26
- const PLACEHOLDER_CLIENT_ID = "000000000000-placeholder.apps.googleusercontent.com";
27
-
28
- function validateGoogleConfig(config?: GoogleAuthConfig): boolean {
29
- if (!config) return false;
30
- return !!(
31
- (config.iosClientId && config.iosClientId !== PLACEHOLDER_CLIENT_ID) ||
32
- (config.webClientId && config.webClientId !== PLACEHOLDER_CLIENT_ID) ||
33
- (config.androidClientId && config.androidClientId !== PLACEHOLDER_CLIENT_ID)
34
- );
35
- }
36
-
37
- export function useGoogleAuth(config?: GoogleAuthConfig): UseGoogleAuthResult {
38
- const [isLoading, setIsLoading] = useState(false);
39
- const [googleError, setGoogleError] = useState<string | null>(null);
40
- const googleConfigured = validateGoogleConfig(config);
41
-
42
- const { signInWithGoogleToken, googleLoading: firebaseLoading } = useSocialAuth({
43
- google: config,
44
- apple: { enabled: false },
45
- } as SocialAuthConfig);
46
-
47
- const authRequest = Google?.useAuthRequest({
48
- iosClientId: config?.iosClientId || PLACEHOLDER_CLIENT_ID,
49
- webClientId: config?.webClientId || PLACEHOLDER_CLIENT_ID,
50
- androidClientId: config?.androidClientId || PLACEHOLDER_CLIENT_ID,
51
- });
52
-
53
- const request = authRequest?.[0] ?? null;
54
- const googleResponse = authRequest?.[1] ?? null;
55
- const promptGoogleAsync = authRequest?.[2];
56
-
57
- useEffect(() => {
58
- if (googleResponse?.type === "success") {
59
- const idToken = googleResponse.authentication?.idToken;
60
- if (idToken) {
61
- setIsLoading(true);
62
- setGoogleError(null);
63
- signInWithGoogleToken(idToken)
64
- .catch((error) => { setGoogleError(error instanceof Error ? error.message : "Firebase sign-in failed"); })
65
- .finally(() => { setIsLoading(false); });
66
- }
67
- } else if (googleResponse?.type === "error") {
68
- setGoogleError("Google authentication failed");
69
- setIsLoading(false);
70
- }
71
- }, [googleResponse, signInWithGoogleToken]);
72
-
73
- const signInWithGoogle = useCallback(async (): Promise<SocialAuthResult> => {
74
- if (!promptGoogleAsync) {
75
- const error = "expo-auth-session is not available";
76
- setGoogleError(error);
77
- return { success: false, error };
78
- }
79
-
80
- if (!googleConfigured) {
81
- const error = "Google Sign-In is not configured. Please provide valid client IDs.";
82
- setGoogleError(error);
83
- return { success: false, error };
84
- }
85
-
86
- if (!request) {
87
- const error = "Google Sign-In not ready";
88
- setGoogleError(error);
89
- return { success: false, error };
90
- }
91
-
92
- setIsLoading(true);
93
- setGoogleError(null);
94
- try {
95
- const result = await promptGoogleAsync();
96
-
97
- if (result.type === "success" && result.authentication?.idToken) {
98
- return await signInWithGoogleToken(result.authentication.idToken);
99
- }
100
-
101
- if (result.type === "cancel") {
102
- const error = "Google Sign-In was cancelled";
103
- setGoogleError(error);
104
- return { success: false, error };
105
- }
106
-
107
- const error = "Google Sign-In failed";
108
- setGoogleError(error);
109
- return { success: false, error };
110
- } catch (error) {
111
- const errorMessage = error instanceof Error ? error.message : "Google sign-in failed";
112
- setGoogleError(errorMessage);
113
- return { success: false, error: errorMessage };
114
- } finally {
115
- setIsLoading(false);
116
- }
117
- }, [googleConfigured, request, promptGoogleAsync, signInWithGoogleToken]);
118
-
119
- return {
120
- signInWithGoogle,
121
- googleLoading: isLoading || firebaseLoading,
122
- googleConfigured,
123
- googleError,
124
- };
125
- }