@atzentis/auth-expo 0.0.16 → 0.1.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/dist/index.d.ts CHANGED
@@ -1,13 +1,429 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React, { ReactNode } from 'react';
3
+ import { TextInputProps, TextInput } from 'react-native';
4
+ import * as _atzentis_auth_locales from '@atzentis/auth-locales';
5
+ import { AuthLocalization } from '@atzentis/auth-locales';
6
+ import * as _tanstack_react_query from '@tanstack/react-query';
7
+ import { QueryClient } from '@tanstack/react-query';
8
+
9
+ interface AuthContainerProps {
10
+ children: ReactNode;
11
+ }
1
12
  /**
2
- * @atzentis/auth-expo - React Native/Expo integration for Atzentis Auth SDK
13
+ * Root layout for auth screens. Handles keyboard avoidance, safe area insets,
14
+ * and centering content on tablets.
15
+ */
16
+ declare function AuthContainer({ children }: AuthContainerProps): react_jsx_runtime.JSX.Element;
17
+
18
+ interface AuthGateProps {
19
+ children: ReactNode;
20
+ fallback?: ReactNode;
21
+ }
22
+ declare function AuthGate({ children, fallback }: AuthGateProps): react_jsx_runtime.JSX.Element;
23
+
24
+ interface ErrorFeedbackProps {
25
+ message: string;
26
+ }
27
+ /**
28
+ * Displays an error message with a red alert icon.
29
+ * Used in auth screens to show validation or API errors.
30
+ */
31
+ declare function ErrorFeedback({ message }: ErrorFeedbackProps): react_jsx_runtime.JSX.Element;
32
+
33
+ interface FormInputProps extends Omit<TextInputProps, "onChangeText" | "value"> {
34
+ error?: string;
35
+ label?: string;
36
+ onChangeText?: (text: string) => void;
37
+ value?: string;
38
+ }
39
+ /**
40
+ * Form text input with optional label and error display.
41
+ * Designed for react-hook-form Controller render prop.
42
+ */
43
+ declare const FormInput: React.ForwardRefExoticComponent<FormInputProps & React.RefAttributes<TextInput>>;
44
+
45
+ interface FormPasswordInputProps extends Omit<TextInputProps, "onChangeText" | "value"> {
46
+ error?: string;
47
+ label?: string;
48
+ onChangeText?: (text: string) => void;
49
+ value?: string;
50
+ }
51
+ /**
52
+ * Form password input with show/hide toggle, optional label and error display.
53
+ * Designed for react-hook-form Controller render prop.
54
+ */
55
+ declare const FormPasswordInput: React.ForwardRefExoticComponent<FormPasswordInputProps & React.RefAttributes<TextInput>>;
56
+
57
+ type OAuthProvider = "google" | "apple" | "github";
58
+ interface OAuthButtonProps {
59
+ disabled?: boolean;
60
+ onError?: (error: Error) => void;
61
+ onSuccess?: () => void;
62
+ provider: OAuthProvider;
63
+ }
64
+ declare function OAuthButton({ disabled, onError, onSuccess, provider }: OAuthButtonProps): react_jsx_runtime.JSX.Element;
65
+
66
+ interface ProtectedScreenProps {
67
+ children: ReactNode;
68
+ fallback?: ReactNode;
69
+ }
70
+ declare function ProtectedScreen({ children, fallback }: ProtectedScreenProps): react_jsx_runtime.JSX.Element | null;
71
+
72
+ interface SuccessFeedbackProps {
73
+ message: string;
74
+ }
75
+ /**
76
+ * Displays a success message with a green checkmark icon.
77
+ */
78
+ declare function SuccessFeedback({ message }: SuccessFeedbackProps): react_jsx_runtime.JSX.Element;
79
+
80
+ interface SubmitButtonProps {
81
+ disabled?: boolean;
82
+ label: string;
83
+ loading: boolean;
84
+ loadingLabel: string;
85
+ onPress: () => void;
86
+ }
87
+ /**
88
+ * Submit button with loading state and optional haptic feedback.
89
+ * Uses @expo/ui Button for native appearance inside Host wrapper.
90
+ */
91
+ declare function SubmitButton({ disabled, label, loading, loadingLabel, onPress, }: SubmitButtonProps): react_jsx_runtime.JSX.Element;
92
+
93
+ /**
94
+ * Available auth screen routes.
95
+ */
96
+ type AuthRoute = "login" | "signup" | "phone-login" | "magic-link" | "forgot-password" | "reset-password" | "verify-email" | "two-factor";
97
+ interface AuthViewProps {
98
+ /** Which auth screen to render. Defaults to "login". */
99
+ route?: AuthRoute;
100
+ /** Called on successful authentication. */
101
+ onSuccess?: () => void;
102
+ /** Token for deep link screens (reset-password, verify-email, magic-link). */
103
+ token?: string;
104
+ /** Whether biometric auth is available (login screen only). */
105
+ biometricAvailable?: boolean;
106
+ /** Handler for biometric button press (login screen only). */
107
+ onBiometricPress?: () => void;
108
+ /** Fallback content when route doesn't match. */
109
+ fallback?: ReactNode;
110
+ }
111
+ /**
112
+ * AuthView — Route-based renderer for auth screens.
113
+ *
114
+ * Maps a route name to the appropriate auth screen component.
115
+ * For use with expo-router layouts or custom navigation.
116
+ *
117
+ * @example
118
+ * // In app/(auth)/[...slug].tsx:
119
+ * import { AuthView } from "@atzentis/auth-expo";
120
+ *
121
+ * export default function AuthRoute() {
122
+ * const { slug } = useLocalSearchParams();
123
+ * const route = (slug as string[])?.[0] ?? "login";
124
+ * const params = useLocalSearchParams();
125
+ * return (
126
+ * <AuthView
127
+ * route={route}
128
+ * token={params.token as string}
129
+ * onSuccess={() => router.replace("/(app)")}
130
+ * />
131
+ * );
132
+ * }
133
+ */
134
+ declare function AuthView({ route, onSuccess, token, biometricAvailable, onBiometricPress, fallback, }: AuthViewProps): react_jsx_runtime.JSX.Element;
135
+
136
+ interface EmailVerificationScreenProps {
137
+ onSuccess?: () => void;
138
+ token?: string;
139
+ }
140
+ /** Auto-verifies an email address using the `token` prop from a deep-link URL. */
141
+ declare function EmailVerificationScreen({ onSuccess, token }: EmailVerificationScreenProps): react_jsx_runtime.JSX.Element;
142
+
143
+ interface ForgotPasswordScreenProps {
144
+ onSuccess?: () => void;
145
+ }
146
+ /** Screen for requesting a password-reset email with a 60-second resend cooldown. */
147
+ declare function ForgotPasswordScreen({ onSuccess }: ForgotPasswordScreenProps): react_jsx_runtime.JSX.Element;
148
+
149
+ interface LoginScreenProps {
150
+ biometricAvailable?: boolean;
151
+ onBiometricPress?: () => void;
152
+ onSuccess?: () => void;
153
+ }
154
+ /** Email/password login screen with optional biometric button (iOS only). */
155
+ declare function LoginScreen({ biometricAvailable, onBiometricPress, onSuccess, }: LoginScreenProps): react_jsx_runtime.JSX.Element;
156
+
157
+ interface MagicLinkScreenProps {
158
+ onSuccess?: () => void;
159
+ token?: string;
160
+ }
161
+ /** Magic-link login screen: sends link via email, then auto-verifies when a `token` prop is provided. */
162
+ declare function MagicLinkScreen({ onSuccess, token }: MagicLinkScreenProps): react_jsx_runtime.JSX.Element;
163
+
164
+ interface PhoneLoginScreenProps {
165
+ onSuccess?: () => void;
166
+ }
167
+ /** Two-step phone login screen: collect phone number, then verify the OTP code sent via SMS. */
168
+ declare function PhoneLoginScreen({ onSuccess }: PhoneLoginScreenProps): react_jsx_runtime.JSX.Element;
169
+
170
+ interface ResetPasswordScreenProps {
171
+ onSuccess?: () => void;
172
+ token?: string;
173
+ }
174
+ /** Token-based password reset screen; shows an error state when no token is provided. */
175
+ declare function ResetPasswordScreen({ onSuccess, token }: ResetPasswordScreenProps): react_jsx_runtime.JSX.Element;
176
+
177
+ interface SignupScreenProps {
178
+ onSuccess?: () => void;
179
+ }
180
+ /** Email/password registration screen with name, email, and password fields. */
181
+ declare function SignupScreen({ onSuccess }: SignupScreenProps): react_jsx_runtime.JSX.Element;
182
+
183
+ interface TwoFactorScreenProps {
184
+ onSuccess?: () => void;
185
+ }
186
+ /** TOTP/backup-code verification screen shown after initial credentials are accepted. */
187
+ declare function TwoFactorScreen({ onSuccess }: TwoFactorScreenProps): react_jsx_runtime.JSX.Element;
188
+
189
+ interface ChangeEmailScreenProps {
190
+ onSuccess?: () => void;
191
+ redirectUrl?: string;
192
+ }
193
+ /** Settings screen for changing the account email address; sends a verification link with a resend cooldown. */
194
+ declare function ChangeEmailScreen({ onSuccess, redirectUrl }: ChangeEmailScreenProps): react_jsx_runtime.JSX.Element;
195
+
196
+ interface ChangePasswordScreenProps {
197
+ onSuccess?: () => void;
198
+ }
199
+ /** Settings screen for changing the current user's password (requires current password). */
200
+ declare function ChangePasswordScreen({ onSuccess }: ChangePasswordScreenProps): react_jsx_runtime.JSX.Element;
201
+
202
+ interface DeleteAccountScreenProps {
203
+ confirmationPhrase?: string;
204
+ onSuccess?: () => void;
205
+ }
206
+ /** Destructive settings screen for permanent account deletion; requires typing a confirmation phrase and password. */
207
+ declare function DeleteAccountScreen({ confirmationPhrase, onSuccess, }: DeleteAccountScreenProps): react_jsx_runtime.JSX.Element;
208
+
209
+ interface SessionsScreenProps {
210
+ onSuccess?: () => void;
211
+ }
212
+ /** Settings screen listing all active sessions with individual revoke and revoke-all-others actions. */
213
+ declare function SessionsScreen({ onSuccess }: SessionsScreenProps): react_jsx_runtime.JSX.Element;
214
+
215
+ interface TwoFactorSettingsScreenProps {
216
+ onSuccess?: () => void;
217
+ }
218
+ /** Settings screen for enabling or disabling TOTP two-factor authentication; shows the secret, verify step, and backup codes. */
219
+ declare function TwoFactorSettingsScreen({ onSuccess }: TwoFactorSettingsScreenProps): react_jsx_runtime.JSX.Element;
220
+
221
+ interface UpdateAvatarScreenProps {
222
+ onSuccess?: () => void;
223
+ }
224
+ /** Settings screen for uploading or removing the current user's avatar using the image library. */
225
+ declare function UpdateAvatarScreen({ onSuccess }: UpdateAvatarScreenProps): react_jsx_runtime.JSX.Element;
226
+
227
+ interface UpdateNameScreenProps {
228
+ onSuccess?: () => void;
229
+ }
230
+ /** Settings screen for updating the current user's display name. */
231
+ declare function UpdateNameScreen({ onSuccess }: UpdateNameScreenProps): react_jsx_runtime.JSX.Element;
232
+
233
+ interface UpdateUsernameScreenProps {
234
+ onSuccess?: () => void;
235
+ }
236
+ /** Settings screen for updating the account username with debounced availability checking. */
237
+ declare function UpdateUsernameScreen({ onSuccess }: UpdateUsernameScreenProps): react_jsx_runtime.JSX.Element;
238
+
239
+ interface OrganizationMembersScreenProps {
240
+ organizationId: string;
241
+ isAdmin?: boolean;
242
+ onSuccess?: () => void;
243
+ }
244
+ /** Screen displaying organization members with role management and removal actions (admin only). */
245
+ declare function OrganizationMembersScreen({ organizationId, isAdmin, onSuccess, }: OrganizationMembersScreenProps): react_jsx_runtime.JSX.Element;
246
+
247
+ interface OrganizationSwitcherScreenProps {
248
+ currentOrgId?: string;
249
+ onSwitch?: (orgId: string) => void;
250
+ }
251
+ /** Screen listing all organizations the user belongs to; selecting one sets it as the active organization. */
252
+ declare function OrganizationSwitcherScreen({ currentOrgId, onSwitch, }: OrganizationSwitcherScreenProps): react_jsx_runtime.JSX.Element;
253
+
254
+ /**
255
+ * Returns the Better Auth client instance from the nearest `AuthProvider`.
256
+ *
257
+ * @throws {Error} If called outside of an `AuthProvider`.
258
+ * @returns The configured Better Auth client with expo plugin.
259
+ */
260
+ declare function useAuthClient(): Record<string, any>;
261
+
262
+ /**
263
+ * Returns the resolved auth localization strings and the `localizeErrors` flag
264
+ * from the nearest `AuthProvider`.
265
+ *
266
+ * @returns `{ localization, localizeErrors }` — use `localization.SIGN_IN` etc. inside SDK screens.
267
+ */
268
+ declare function useAuthLocalization(): {
269
+ localization: _atzentis_auth_locales.AuthLocalization;
270
+ localizeErrors: boolean;
271
+ };
272
+
273
+ declare function useAuthRedirect(): {
274
+ redirectToSignIn: (returnUrl?: string) => void;
275
+ redirectToSignUp: (returnUrl?: string) => void;
276
+ };
277
+
278
+ interface BiometricAvailability {
279
+ hasHardware: boolean;
280
+ isEnrolled: boolean;
281
+ supportedTypes: number[];
282
+ }
283
+ /**
284
+ * Hook for biometric authentication (Face ID / Touch ID / fingerprint).
285
+ *
286
+ * @returns An object with:
287
+ * - `checkAvailability` — async function that resolves with `{ hasHardware, isEnrolled, supportedTypes }`.
288
+ * - `authenticate` — TanStack mutation that accepts a `promptMessage` string and triggers the system biometric prompt.
289
+ *
290
+ * @example
291
+ * ```tsx
292
+ * const { checkAvailability, authenticate } = useBiometric();
293
+ * const available = await checkAvailability();
294
+ * if (available.isEnrolled) {
295
+ * authenticate.mutate("Authenticate to sign in");
296
+ * }
297
+ * ```
298
+ */
299
+ declare function useBiometric(): {
300
+ checkAvailability: () => Promise<BiometricAvailability>;
301
+ authenticate: _tanstack_react_query.UseMutationResult<{
302
+ success: boolean;
303
+ error?: string;
304
+ }, Error, string, unknown>;
305
+ };
306
+
307
+ interface LoginInput {
308
+ email: string;
309
+ password: string;
310
+ }
311
+ /**
312
+ * Mutation hook for email/password login.
313
+ *
314
+ * On success, writes the returned user and session into the TanStack Query cache
315
+ * via the `authKeys` factory so that `useUser` and `useSession` update immediately.
3
316
  *
4
- * Provides:
5
- * - Secure token storage via expo-secure-store
6
- * - Native device signal collection
7
- * - OAuth deep linking handler
8
- * - Push notification token management
9
- * - Phone sign-in screen
317
+ * @returns A TanStack `UseMutationResult` — call `.mutate({ email, password })` to sign in.
10
318
  */
11
- declare const VERSION = "0.0.1";
319
+ declare function useLogin(): _tanstack_react_query.UseMutationResult<any, Error, LoginInput, unknown>;
320
+
321
+ /**
322
+ * Mutation hook for signing out the current user.
323
+ *
324
+ * On success, sets user and session cache to `null` and invalidates all
325
+ * session-related queries so the UI reflects the signed-out state immediately.
326
+ *
327
+ * @returns A TanStack `UseMutationResult` — call `.mutate()` with no arguments to sign out.
328
+ */
329
+ declare function useLogout(): _tanstack_react_query.UseMutationResult<any, Error, void, unknown>;
330
+
331
+ interface RequestPasswordResetInput {
332
+ email: string;
333
+ redirectTo?: string;
334
+ }
335
+ /**
336
+ * Mutation hook for requesting a password reset email.
337
+ */
338
+ declare function useRequestPasswordReset(): _tanstack_react_query.UseMutationResult<boolean, Error, RequestPasswordResetInput, unknown>;
339
+
340
+ interface ResetPasswordInput {
341
+ newPassword: string;
342
+ token: string;
343
+ }
344
+ /**
345
+ * Mutation hook for resetting a password using a token from the reset email.
346
+ */
347
+ declare function useResetPassword(): _tanstack_react_query.UseMutationResult<boolean, Error, ResetPasswordInput, unknown>;
348
+
349
+ interface SignupInput {
350
+ email: string;
351
+ name: string;
352
+ password: string;
353
+ }
354
+ /**
355
+ * Mutation hook for email/password signup.
356
+ *
357
+ * On success, writes the returned user and session into the TanStack Query cache
358
+ * via the `authKeys` factory so that `useUser` and `useSession` update immediately.
359
+ *
360
+ * @returns A TanStack `UseMutationResult` — call `.mutate({ email, name, password })` to register.
361
+ */
362
+ declare function useSignup(): _tanstack_react_query.UseMutationResult<any, Error, SignupInput, unknown>;
363
+
364
+ /**
365
+ * Query hook for the current session.
366
+ *
367
+ * Fetches via `client.getSession()` and extracts the session object.
368
+ * Data is cached for 5 minutes (`staleTime`). Returns `null` when not authenticated.
369
+ *
370
+ * @returns A TanStack `UseQueryResult<Session | null>`.
371
+ */
372
+ declare function useSession(): _tanstack_react_query.UseQueryResult<any, Error>;
373
+
374
+ /**
375
+ * Query hook for the current authenticated user.
376
+ *
377
+ * Fetches via `client.getSession()` and extracts the user object.
378
+ * Data is cached for 5 minutes (`staleTime`). Returns `null` when not authenticated.
379
+ *
380
+ * @returns A TanStack `UseQueryResult<User | null>`.
381
+ */
382
+ declare function useUser(): _tanstack_react_query.UseQueryResult<any, Error>;
383
+
384
+ interface AuthProviderProps {
385
+ baseURL: string;
386
+ children: React.ReactNode;
387
+ locales?: Record<string, AuthLocalization>;
388
+ localization?: Partial<AuthLocalization>;
389
+ queryClient?: QueryClient;
390
+ }
391
+ /**
392
+ * Provides authentication context for Expo/React Native applications.
393
+ *
394
+ * Wraps Better Auth client with SecureStore for token persistence and
395
+ * expo-localization for automatic language detection.
396
+ *
397
+ * @param props - Provider configuration
398
+ * @param props.baseURL - Base URL of the Better Auth server
399
+ * @param props.children - Child components
400
+ * @param props.locales - Language packs keyed by BCP 47 language code (e.g. `{ el, de }`)
401
+ * @param props.localization - Per-key overrides applied on top of the resolved locale
402
+ * @param props.queryClient - Optional external TanStack QueryClient; a default one is created if omitted
403
+ * @returns JSX element wrapping children with auth, localization, and query contexts
404
+ *
405
+ * @example
406
+ * ```tsx
407
+ * import { el, de } from "@atzentis/auth-locales";
408
+ *
409
+ * export default function RootLayout() {
410
+ * return (
411
+ * <AuthProvider
412
+ * baseURL="https://auth.example.com"
413
+ * locales={{ el, de }}
414
+ * >
415
+ * <Slot />
416
+ * </AuthProvider>
417
+ * );
418
+ * }
419
+ * ```
420
+ */
421
+ declare function AuthProvider({ baseURL, children, locales, localization: localizationOverride, queryClient: externalQueryClient, }: AuthProviderProps): react_jsx_runtime.JSX.Element;
422
+
423
+ /**
424
+ * @atzentis/auth-expo - React Native/Expo integration for Atzentis Auth SDK
425
+ */
426
+
427
+ declare const VERSION = "0.1.0";
12
428
 
13
- export { VERSION };
429
+ export { AuthContainer, AuthGate, type AuthGateProps, AuthProvider, type AuthRoute, AuthView, type AuthViewProps, ChangeEmailScreen, type ChangeEmailScreenProps, ChangePasswordScreen, type ChangePasswordScreenProps, DeleteAccountScreen, type DeleteAccountScreenProps, EmailVerificationScreen, type EmailVerificationScreenProps, ErrorFeedback, ForgotPasswordScreen, type ForgotPasswordScreenProps, FormInput, FormPasswordInput, LoginScreen, type LoginScreenProps, MagicLinkScreen, type MagicLinkScreenProps, OAuthButton, type OAuthButtonProps, OrganizationMembersScreen, type OrganizationMembersScreenProps, OrganizationSwitcherScreen, type OrganizationSwitcherScreenProps, PhoneLoginScreen, type PhoneLoginScreenProps, ProtectedScreen, type ProtectedScreenProps, ResetPasswordScreen, type ResetPasswordScreenProps, SessionsScreen, type SessionsScreenProps, SignupScreen, type SignupScreenProps, SubmitButton, SuccessFeedback, TwoFactorScreen, type TwoFactorScreenProps, TwoFactorSettingsScreen, type TwoFactorSettingsScreenProps, UpdateAvatarScreen, type UpdateAvatarScreenProps, UpdateNameScreen, type UpdateNameScreenProps, UpdateUsernameScreen, type UpdateUsernameScreenProps, VERSION, useAuthClient, useAuthLocalization, useAuthRedirect, useBiometric, useLogin, useLogout, useRequestPasswordReset, useResetPassword, useSession, useSignup, useUser };