@umituz/react-native-firebase 2.0.3 → 2.1.1
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/domains/account-deletion/index.ts +6 -0
- package/src/domains/account-deletion/infrastructure/services/account-deletion.service.ts +28 -4
- package/src/domains/account-deletion/presentation/components/PasswordPromptModal.tsx +106 -0
- package/src/domains/account-deletion/presentation/hooks/usePasswordPrompt.tsx +64 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-firebase",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Unified Firebase package for React Native apps - Auth and Firestore services using Firebase JS SDK (no native modules).",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -26,3 +26,9 @@ export {
|
|
|
26
26
|
reauthenticateWithApple,
|
|
27
27
|
getAppleReauthCredential,
|
|
28
28
|
} from './infrastructure/services/reauthentication.service';
|
|
29
|
+
|
|
30
|
+
export { PasswordPromptModal } from './presentation/components/PasswordPromptModal';
|
|
31
|
+
export type { PasswordPromptModalProps } from './presentation/components/PasswordPromptModal';
|
|
32
|
+
|
|
33
|
+
export { usePasswordPrompt } from './presentation/hooks/usePasswordPrompt';
|
|
34
|
+
export type { UsePasswordPromptOptions, UsePasswordPromptReturn } from './presentation/hooks/usePasswordPrompt';
|
|
@@ -74,23 +74,47 @@ async function attemptReauth(user: User, options: AccountDeletionOptions): Promi
|
|
|
74
74
|
if (provider === "apple.com") {
|
|
75
75
|
res = await reauthenticateWithApple(user);
|
|
76
76
|
} else if (provider === "google.com") {
|
|
77
|
-
|
|
77
|
+
let googleToken = options.googleIdToken;
|
|
78
|
+
if (!googleToken && options.onGoogleReauthRequired) {
|
|
79
|
+
const token = await options.onGoogleReauthRequired();
|
|
80
|
+
if (!token) {
|
|
81
|
+
return {
|
|
82
|
+
success: false,
|
|
83
|
+
error: { code: "auth/google-reauth-cancelled", message: "Google reauth cancelled" },
|
|
84
|
+
requiresReauth: true
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
googleToken = token;
|
|
88
|
+
}
|
|
89
|
+
if (!googleToken) {
|
|
78
90
|
return {
|
|
79
91
|
success: false,
|
|
80
92
|
error: { code: "auth/google-reauth", message: "Google reauth required" },
|
|
81
93
|
requiresReauth: true
|
|
82
94
|
};
|
|
83
95
|
}
|
|
84
|
-
res = await reauthenticateWithGoogle(user,
|
|
96
|
+
res = await reauthenticateWithGoogle(user, googleToken);
|
|
85
97
|
} else if (provider === "password") {
|
|
86
|
-
|
|
98
|
+
let password = options.password;
|
|
99
|
+
if (!password && options.onPasswordRequired) {
|
|
100
|
+
const pwd = await options.onPasswordRequired();
|
|
101
|
+
if (!pwd) {
|
|
102
|
+
return {
|
|
103
|
+
success: false,
|
|
104
|
+
error: { code: "auth/password-reauth-cancelled", message: "Password reauth cancelled" },
|
|
105
|
+
requiresReauth: true
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
password = pwd;
|
|
109
|
+
}
|
|
110
|
+
if (!password) {
|
|
87
111
|
return {
|
|
88
112
|
success: false,
|
|
89
113
|
error: { code: "auth/password-reauth", message: "Password required" },
|
|
90
114
|
requiresReauth: true
|
|
91
115
|
};
|
|
92
116
|
}
|
|
93
|
-
res = await reauthenticateWithPassword(user,
|
|
117
|
+
res = await reauthenticateWithPassword(user, password);
|
|
94
118
|
} else {
|
|
95
119
|
return null;
|
|
96
120
|
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Password Prompt Modal
|
|
3
|
+
* Modal for password input during account deletion reauthentication
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { useState } from 'react';
|
|
7
|
+
import { View, StyleSheet } from 'react-native';
|
|
8
|
+
import {
|
|
9
|
+
BaseModal,
|
|
10
|
+
AtomicInput,
|
|
11
|
+
AtomicButton,
|
|
12
|
+
useAppDesignTokens
|
|
13
|
+
} from '@umituz/react-native-design-system';
|
|
14
|
+
|
|
15
|
+
export interface PasswordPromptModalProps {
|
|
16
|
+
visible: boolean;
|
|
17
|
+
onConfirm: (password: string) => void;
|
|
18
|
+
onCancel: () => void;
|
|
19
|
+
title?: string;
|
|
20
|
+
message?: string;
|
|
21
|
+
confirmText?: string;
|
|
22
|
+
cancelText?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const PasswordPromptModal: React.FC<PasswordPromptModalProps> = ({
|
|
26
|
+
visible,
|
|
27
|
+
onConfirm,
|
|
28
|
+
onCancel,
|
|
29
|
+
title = 'Password Required',
|
|
30
|
+
message = 'Enter your password to continue',
|
|
31
|
+
confirmText = 'Confirm',
|
|
32
|
+
cancelText = 'Cancel',
|
|
33
|
+
}) => {
|
|
34
|
+
const tokens = useAppDesignTokens();
|
|
35
|
+
const [password, setPassword] = useState('');
|
|
36
|
+
const [error, setError] = useState('');
|
|
37
|
+
|
|
38
|
+
const handleConfirm = () => {
|
|
39
|
+
if (!password.trim()) {
|
|
40
|
+
setError('Password is required');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
onConfirm(password);
|
|
44
|
+
setPassword('');
|
|
45
|
+
setError('');
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const handleCancel = () => {
|
|
49
|
+
setPassword('');
|
|
50
|
+
setError('');
|
|
51
|
+
onCancel();
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<BaseModal
|
|
56
|
+
visible={visible}
|
|
57
|
+
onClose={handleCancel}
|
|
58
|
+
title={title}
|
|
59
|
+
subtitle={message}
|
|
60
|
+
dismissOnBackdrop={false}
|
|
61
|
+
>
|
|
62
|
+
<View style={[styles.container, { padding: tokens.spacing.md }]}>
|
|
63
|
+
<AtomicInput
|
|
64
|
+
value={password}
|
|
65
|
+
onChangeText={(text: string) => {
|
|
66
|
+
setPassword(text);
|
|
67
|
+
setError('');
|
|
68
|
+
}}
|
|
69
|
+
placeholder="Password"
|
|
70
|
+
secureTextEntry
|
|
71
|
+
autoFocus
|
|
72
|
+
state={error ? 'error' : 'default'}
|
|
73
|
+
helperText={error}
|
|
74
|
+
style={{ marginBottom: tokens.spacing.md }}
|
|
75
|
+
/>
|
|
76
|
+
|
|
77
|
+
<View style={[styles.buttons, { gap: tokens.spacing.sm }]}>
|
|
78
|
+
<AtomicButton
|
|
79
|
+
title={cancelText}
|
|
80
|
+
onPress={handleCancel}
|
|
81
|
+
variant="secondary"
|
|
82
|
+
style={styles.button}
|
|
83
|
+
/>
|
|
84
|
+
<AtomicButton
|
|
85
|
+
title={confirmText}
|
|
86
|
+
onPress={handleConfirm}
|
|
87
|
+
variant="primary"
|
|
88
|
+
style={styles.button}
|
|
89
|
+
/>
|
|
90
|
+
</View>
|
|
91
|
+
</View>
|
|
92
|
+
</BaseModal>
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const styles = StyleSheet.create({
|
|
97
|
+
container: {
|
|
98
|
+
width: '100%',
|
|
99
|
+
},
|
|
100
|
+
buttons: {
|
|
101
|
+
flexDirection: 'row',
|
|
102
|
+
},
|
|
103
|
+
button: {
|
|
104
|
+
flex: 1,
|
|
105
|
+
},
|
|
106
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Password Prompt Hook
|
|
3
|
+
* Manages password prompt modal state and logic
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { useState, useCallback, useMemo } from 'react';
|
|
7
|
+
import { PasswordPromptModal } from '../components/PasswordPromptModal';
|
|
8
|
+
|
|
9
|
+
export interface UsePasswordPromptOptions {
|
|
10
|
+
title?: string;
|
|
11
|
+
message?: string;
|
|
12
|
+
confirmText?: string;
|
|
13
|
+
cancelText?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface UsePasswordPromptReturn {
|
|
17
|
+
showPasswordPrompt: () => Promise<string | null>;
|
|
18
|
+
PasswordPromptComponent: React.ReactNode;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const usePasswordPrompt = (options: UsePasswordPromptOptions = {}): UsePasswordPromptReturn => {
|
|
22
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
23
|
+
const [resolvePromise, setResolvePromise] = useState<((value: string | null) => void) | null>(null);
|
|
24
|
+
|
|
25
|
+
const showPasswordPrompt = useCallback((): Promise<string | null> => {
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
setResolvePromise(() => resolve);
|
|
28
|
+
setIsVisible(true);
|
|
29
|
+
});
|
|
30
|
+
}, []);
|
|
31
|
+
|
|
32
|
+
const handleConfirm = useCallback((password: string) => {
|
|
33
|
+
if (resolvePromise) {
|
|
34
|
+
resolvePromise(password);
|
|
35
|
+
}
|
|
36
|
+
setIsVisible(false);
|
|
37
|
+
setResolvePromise(null);
|
|
38
|
+
}, [resolvePromise]);
|
|
39
|
+
|
|
40
|
+
const handleCancel = useCallback(() => {
|
|
41
|
+
if (resolvePromise) {
|
|
42
|
+
resolvePromise(null);
|
|
43
|
+
}
|
|
44
|
+
setIsVisible(false);
|
|
45
|
+
setResolvePromise(null);
|
|
46
|
+
}, [resolvePromise]);
|
|
47
|
+
|
|
48
|
+
const PasswordPromptComponent = useMemo(() => (
|
|
49
|
+
<PasswordPromptModal
|
|
50
|
+
visible={isVisible}
|
|
51
|
+
onConfirm={handleConfirm}
|
|
52
|
+
onCancel={handleCancel}
|
|
53
|
+
title={options.title}
|
|
54
|
+
message={options.message}
|
|
55
|
+
confirmText={options.confirmText}
|
|
56
|
+
cancelText={options.cancelText}
|
|
57
|
+
/>
|
|
58
|
+
), [isVisible, handleConfirm, handleCancel, options.title, options.message, options.confirmText, options.cancelText]);
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
showPasswordPrompt,
|
|
62
|
+
PasswordPromptComponent,
|
|
63
|
+
};
|
|
64
|
+
};
|