@croacroa/react-native-template 1.0.0 → 2.0.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/.github/workflows/ci.yml +187 -184
- package/.github/workflows/eas-build.yml +55 -55
- package/.github/workflows/eas-update.yml +50 -50
- package/CHANGELOG.md +106 -106
- package/CONTRIBUTING.md +377 -377
- package/README.md +399 -399
- package/__tests__/components/snapshots.test.tsx +131 -0
- package/__tests__/integration/auth-api.test.tsx +227 -0
- package/__tests__/performance/VirtualizedList.perf.test.tsx +362 -0
- package/app/(public)/onboarding.tsx +5 -5
- package/app.config.ts +45 -2
- package/assets/images/.gitkeep +7 -7
- package/components/onboarding/OnboardingScreen.tsx +370 -370
- package/components/onboarding/index.ts +2 -2
- package/components/providers/SuspenseBoundary.tsx +357 -0
- package/components/providers/index.ts +13 -0
- package/components/ui/Avatar.tsx +316 -316
- package/components/ui/Badge.tsx +416 -416
- package/components/ui/BottomSheet.tsx +307 -307
- package/components/ui/Checkbox.tsx +261 -261
- package/components/ui/OptimizedImage.tsx +369 -369
- package/components/ui/Select.tsx +240 -240
- package/components/ui/VirtualizedList.tsx +285 -0
- package/components/ui/index.ts +23 -18
- package/constants/config.ts +97 -54
- package/docs/adr/001-state-management.md +79 -79
- package/docs/adr/002-styling-approach.md +130 -130
- package/docs/adr/003-data-fetching.md +155 -155
- package/docs/adr/004-auth-adapter-pattern.md +144 -144
- package/docs/adr/README.md +78 -78
- package/hooks/index.ts +27 -25
- package/hooks/useApi.ts +102 -5
- package/hooks/useAuth.tsx +82 -0
- package/hooks/useBiometrics.ts +295 -295
- package/hooks/useDeepLinking.ts +256 -256
- package/hooks/useMFA.ts +499 -0
- package/hooks/useNotifications.ts +39 -0
- package/hooks/useOffline.ts +32 -2
- package/hooks/usePerformance.ts +434 -434
- package/hooks/useTheme.tsx +76 -0
- package/hooks/useUpdates.ts +358 -358
- package/i18n/index.ts +194 -77
- package/i18n/locales/ar.json +101 -0
- package/i18n/locales/de.json +101 -0
- package/i18n/locales/en.json +101 -101
- package/i18n/locales/es.json +101 -0
- package/i18n/locales/fr.json +101 -101
- package/jest.config.js +4 -4
- package/maestro/README.md +113 -113
- package/maestro/config.yaml +35 -35
- package/maestro/flows/login.yaml +62 -62
- package/maestro/flows/mfa-login.yaml +92 -0
- package/maestro/flows/mfa-setup.yaml +86 -0
- package/maestro/flows/navigation.yaml +68 -68
- package/maestro/flows/offline-conflict.yaml +101 -0
- package/maestro/flows/offline-sync.yaml +128 -0
- package/maestro/flows/offline.yaml +60 -60
- package/maestro/flows/register.yaml +94 -94
- package/package.json +175 -170
- package/services/analytics.ts +428 -428
- package/services/api.ts +340 -340
- package/services/authAdapter.ts +333 -333
- package/services/backgroundSync.ts +626 -0
- package/services/index.ts +54 -22
- package/services/security.ts +229 -0
- package/tailwind.config.js +47 -47
- package/utils/accessibility.ts +446 -446
- package/utils/index.ts +52 -43
- package/utils/withAccessibility.tsx +272 -0
package/hooks/useAuth.tsx
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Authentication context and hooks
|
|
3
|
+
* Provides secure authentication with token management, auto-refresh, and persistent sessions.
|
|
4
|
+
* @module hooks/useAuth
|
|
5
|
+
*/
|
|
6
|
+
|
|
1
7
|
import {
|
|
2
8
|
createContext,
|
|
3
9
|
useContext,
|
|
@@ -10,6 +16,9 @@ import * as SecureStore from "expo-secure-store";
|
|
|
10
16
|
import { router } from "expo-router";
|
|
11
17
|
import { toast } from "@/utils/toast";
|
|
12
18
|
|
|
19
|
+
/**
|
|
20
|
+
* User profile information
|
|
21
|
+
*/
|
|
13
22
|
interface User {
|
|
14
23
|
id: string;
|
|
15
24
|
email: string;
|
|
@@ -23,14 +32,26 @@ interface AuthTokens {
|
|
|
23
32
|
expiresAt: number;
|
|
24
33
|
}
|
|
25
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Authentication context type definition.
|
|
37
|
+
* Provides all authentication-related state and actions.
|
|
38
|
+
*/
|
|
26
39
|
interface AuthContextType {
|
|
40
|
+
/** Currently authenticated user, or null if not authenticated */
|
|
27
41
|
user: User | null;
|
|
42
|
+
/** Whether the user is currently authenticated */
|
|
28
43
|
isAuthenticated: boolean;
|
|
44
|
+
/** Whether the auth state is still loading (e.g., checking stored tokens) */
|
|
29
45
|
isLoading: boolean;
|
|
46
|
+
/** Sign in with email and password */
|
|
30
47
|
signIn: (email: string, password: string) => Promise<void>;
|
|
48
|
+
/** Create a new account */
|
|
31
49
|
signUp: (email: string, password: string, name: string) => Promise<void>;
|
|
50
|
+
/** Sign out and clear all stored credentials */
|
|
32
51
|
signOut: () => Promise<void>;
|
|
52
|
+
/** Update the current user's profile locally */
|
|
33
53
|
updateUser: (user: Partial<User>) => void;
|
|
54
|
+
/** Manually refresh the session tokens */
|
|
34
55
|
refreshSession: () => Promise<boolean>;
|
|
35
56
|
}
|
|
36
57
|
|
|
@@ -40,6 +61,32 @@ const TOKEN_KEY = "auth_tokens";
|
|
|
40
61
|
const USER_KEY = "auth_user";
|
|
41
62
|
const TOKEN_REFRESH_THRESHOLD = 5 * 60 * 1000; // 5 minutes before expiry
|
|
42
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Authentication Provider component.
|
|
66
|
+
* Wraps your app to provide authentication context to all children.
|
|
67
|
+
*
|
|
68
|
+
* Features:
|
|
69
|
+
* - Automatic token refresh before expiry
|
|
70
|
+
* - Secure token storage (iOS Keychain / Android Encrypted SharedPreferences)
|
|
71
|
+
* - Persistent sessions across app restarts
|
|
72
|
+
* - Automatic session validation on app launch
|
|
73
|
+
*
|
|
74
|
+
* @param children - Child components to wrap
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```tsx
|
|
78
|
+
* // In your app root (_layout.tsx)
|
|
79
|
+
* export default function RootLayout() {
|
|
80
|
+
* return (
|
|
81
|
+
* <AuthProvider>
|
|
82
|
+
* <ThemeProvider>
|
|
83
|
+
* <App />
|
|
84
|
+
* </ThemeProvider>
|
|
85
|
+
* </AuthProvider>
|
|
86
|
+
* );
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
43
90
|
export function AuthProvider({ children }: { children: ReactNode }) {
|
|
44
91
|
const [user, setUser] = useState<User | null>(null);
|
|
45
92
|
const [tokens, setTokens] = useState<AuthTokens | null>(null);
|
|
@@ -256,6 +303,41 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|
|
256
303
|
);
|
|
257
304
|
}
|
|
258
305
|
|
|
306
|
+
/**
|
|
307
|
+
* Hook to access authentication state and actions.
|
|
308
|
+
* Must be used within an AuthProvider.
|
|
309
|
+
*
|
|
310
|
+
* @returns Authentication context with user, state, and actions
|
|
311
|
+
* @throws Error if used outside of AuthProvider
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```tsx
|
|
315
|
+
* function LoginScreen() {
|
|
316
|
+
* const { signIn, isLoading } = useAuth();
|
|
317
|
+
* const [email, setEmail] = useState('');
|
|
318
|
+
* const [password, setPassword] = useState('');
|
|
319
|
+
*
|
|
320
|
+
* const handleLogin = async () => {
|
|
321
|
+
* try {
|
|
322
|
+
* await signIn(email, password);
|
|
323
|
+
* // Navigation happens automatically via router
|
|
324
|
+
* } catch (error) {
|
|
325
|
+
* // Error toast is shown automatically
|
|
326
|
+
* }
|
|
327
|
+
* };
|
|
328
|
+
*
|
|
329
|
+
* return (
|
|
330
|
+
* <View>
|
|
331
|
+
* <Input value={email} onChangeText={setEmail} />
|
|
332
|
+
* <Input value={password} onChangeText={setPassword} secureTextEntry />
|
|
333
|
+
* <Button onPress={handleLogin} isLoading={isLoading}>
|
|
334
|
+
* Sign In
|
|
335
|
+
* </Button>
|
|
336
|
+
* </View>
|
|
337
|
+
* );
|
|
338
|
+
* }
|
|
339
|
+
* ```
|
|
340
|
+
*/
|
|
259
341
|
export function useAuth() {
|
|
260
342
|
const context = useContext(AuthContext);
|
|
261
343
|
if (context === undefined) {
|