@umituz/react-native-auth 3.4.38 → 3.4.39
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.4.
|
|
3
|
+
"version": "3.4.39",
|
|
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",
|
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* useAccountManagement Hook
|
|
3
3
|
* Provides account management functionality (logout, delete)
|
|
4
|
-
* Generic hook - reauthentication is handled via callback from calling app
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
6
|
import { useCallback, useState } from "react";
|
|
7
|
+
import { Alert } from "react-native";
|
|
8
8
|
import { useAuth } from "./useAuth";
|
|
9
9
|
import { handleAccountDeletion } from "../utils/accountDeleteHandler.util";
|
|
10
10
|
|
|
11
11
|
export interface UseAccountManagementOptions {
|
|
12
12
|
/**
|
|
13
13
|
* Callback invoked when reauthentication is required (for Google/Apple)
|
|
14
|
-
* App should show appropriate UI (Google/Apple sign-in) and return success status
|
|
15
|
-
* If not provided, reauthentication errors will be thrown
|
|
16
14
|
*/
|
|
17
15
|
onReauthRequired?: () => Promise<boolean>;
|
|
18
16
|
/**
|
|
19
|
-
* Callback invoked when password reauthentication is required
|
|
20
|
-
*
|
|
17
|
+
* Callback invoked when password reauthentication is required
|
|
18
|
+
* If not provided, built-in Alert.prompt will be used
|
|
21
19
|
*/
|
|
22
20
|
onPasswordRequired?: () => Promise<string | null>;
|
|
21
|
+
/**
|
|
22
|
+
* Translations for built-in password prompt
|
|
23
|
+
*/
|
|
24
|
+
passwordPromptTitle?: string;
|
|
25
|
+
passwordPromptMessage?: string;
|
|
26
|
+
passwordPromptCancel?: string;
|
|
27
|
+
passwordPromptConfirm?: string;
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
export interface UseAccountManagementReturn {
|
|
@@ -34,7 +39,31 @@ export const useAccountManagement = (
|
|
|
34
39
|
): UseAccountManagementReturn => {
|
|
35
40
|
const { user, loading, signOut } = useAuth();
|
|
36
41
|
const [isDeletingAccount, setIsDeletingAccount] = useState(false);
|
|
37
|
-
|
|
42
|
+
|
|
43
|
+
const {
|
|
44
|
+
onReauthRequired,
|
|
45
|
+
onPasswordRequired,
|
|
46
|
+
passwordPromptTitle = "Password Required",
|
|
47
|
+
passwordPromptMessage = "Enter your password to delete account",
|
|
48
|
+
passwordPromptCancel = "Cancel",
|
|
49
|
+
passwordPromptConfirm = "Confirm",
|
|
50
|
+
} = options;
|
|
51
|
+
|
|
52
|
+
const defaultPasswordPrompt = useCallback((): Promise<string | null> => {
|
|
53
|
+
return new Promise((resolve) => {
|
|
54
|
+
Alert.prompt(
|
|
55
|
+
passwordPromptTitle,
|
|
56
|
+
passwordPromptMessage,
|
|
57
|
+
[
|
|
58
|
+
{ text: passwordPromptCancel, style: "cancel", onPress: () => resolve(null) },
|
|
59
|
+
{ text: passwordPromptConfirm, onPress: (pwd) => resolve(pwd || null) },
|
|
60
|
+
],
|
|
61
|
+
"secure-text"
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
}, [passwordPromptTitle, passwordPromptMessage, passwordPromptCancel, passwordPromptConfirm]);
|
|
65
|
+
|
|
66
|
+
const passwordHandler = onPasswordRequired || defaultPasswordPrompt;
|
|
38
67
|
|
|
39
68
|
const logout = useCallback(async () => {
|
|
40
69
|
await signOut();
|
|
@@ -59,11 +88,14 @@ export const useAccountManagement = (
|
|
|
59
88
|
setIsDeletingAccount(true);
|
|
60
89
|
|
|
61
90
|
try {
|
|
62
|
-
await handleAccountDeletion({
|
|
91
|
+
await handleAccountDeletion({
|
|
92
|
+
onReauthRequired,
|
|
93
|
+
onPasswordRequired: passwordHandler,
|
|
94
|
+
});
|
|
63
95
|
} finally {
|
|
64
96
|
setIsDeletingAccount(false);
|
|
65
97
|
}
|
|
66
|
-
}, [user, onReauthRequired,
|
|
98
|
+
}, [user, onReauthRequired, passwordHandler]);
|
|
67
99
|
|
|
68
100
|
return {
|
|
69
101
|
logout,
|
|
@@ -58,7 +58,7 @@ async function handleReauthentication(
|
|
|
58
58
|
const { onReauthRequired, onPasswordRequired } = callbacks;
|
|
59
59
|
|
|
60
60
|
// Handle password reauth
|
|
61
|
-
if (initialResult.error?.code === "auth/password-reauth
|
|
61
|
+
if (initialResult.error?.code === "auth/password-reauth" && onPasswordRequired) {
|
|
62
62
|
await retryWithPassword(onPasswordRequired);
|
|
63
63
|
return;
|
|
64
64
|
}
|