@umituz/react-native-firebase 2.4.59 → 2.4.61

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-firebase",
3
- "version": "2.4.59",
3
+ "version": "2.4.61",
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",
@@ -16,9 +16,10 @@ import { Platform } from "react-native";
16
16
  * Lazy-loads expo-apple-authentication (optional peer dependency).
17
17
  * Returns null if the package is not installed.
18
18
  */
19
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
- function getAppleAuthModule(): any {
19
+ function getAppleAuthModule(): typeof import("expo-apple-authentication") | null {
21
20
  try {
21
+ // Dynamic require needed for optional peer dependency
22
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
22
23
  return require("expo-apple-authentication");
23
24
  } catch {
24
25
  return null;
@@ -26,3 +26,5 @@ export interface GoogleAuthErrorResult {
26
26
 
27
27
  export type GoogleAuthResult = GoogleAuthSuccessResult | GoogleAuthErrorResult;
28
28
 
29
+ export const PLACEHOLDER_CLIENT_ID = "000000000000-placeholder.apps.googleusercontent.com";
30
+
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import type { Auth } from "firebase/auth";
8
- import type { GoogleAuthResult } from "./google-auth.types";
8
+ import { PLACEHOLDER_CLIENT_ID, type GoogleAuthResult } from "./google-auth.types";
9
9
  import { googleAuthService } from "./google-auth.service";
10
10
 
11
11
  // Conditional import - expo-web-browser is optional
@@ -32,8 +32,6 @@ export interface GoogleOAuthConfig {
32
32
  androidClientId?: string;
33
33
  }
34
34
 
35
- const PLACEHOLDER_CLIENT_ID = "000000000000-placeholder.apps.googleusercontent.com";
36
-
37
35
  function validateGoogleConfig(config?: GoogleOAuthConfig): boolean {
38
36
  if (!config) return false;
39
37
  return !!(
@@ -3,7 +3,7 @@
3
3
  * Builds user document data for Firestore (max 100 lines)
4
4
  */
5
5
 
6
- import { serverTimestamp } from "firebase/firestore";
6
+ import { serverTimestamp, increment } from "firebase/firestore";
7
7
  import type {
8
8
  UserDocumentUser,
9
9
  UserDocumentExtras,
@@ -82,6 +82,7 @@ export function buildCreateData(
82
82
  createdAt: serverTimestamp(),
83
83
  updatedAt: serverTimestamp(),
84
84
  lastLoginAt: serverTimestamp(),
85
+ loginCount: 1,
85
86
  };
86
87
 
87
88
  if (extras?.previousAnonymousUserId) {
@@ -106,6 +107,7 @@ export function buildUpdateData(
106
107
  ...baseData,
107
108
  lastLoginAt: serverTimestamp(),
108
109
  updatedAt: serverTimestamp(),
110
+ loginCount: increment(1),
109
111
  };
110
112
 
111
113
  if (extras?.previousAnonymousUserId) {
@@ -117,3 +119,33 @@ export function buildUpdateData(
117
119
 
118
120
  return updateData;
119
121
  }
122
+
123
+ /**
124
+ * Builds a login history entry for the loginHistory subcollection
125
+ */
126
+ export function buildLoginHistoryEntry(
127
+ user: UserDocumentUser,
128
+ extras?: UserDocumentExtras,
129
+ ): Record<string, unknown> {
130
+ return {
131
+ loginAt: serverTimestamp(),
132
+ provider: getSignUpMethod(user) ?? "unknown",
133
+ email: user.email ?? null,
134
+ displayName: user.displayName ?? null,
135
+ isAnonymous: user.isAnonymous ?? false,
136
+ platform: extras?.platform ?? null,
137
+ deviceModel: extras?.deviceModel ?? null,
138
+ deviceBrand: extras?.deviceBrand ?? null,
139
+ osName: extras?.osName ?? null,
140
+ osVersion: extras?.osVersion ?? null,
141
+ appVersion: extras?.appVersion ?? null,
142
+ buildNumber: extras?.buildNumber ?? null,
143
+ locale: extras?.locale ?? null,
144
+ region: extras?.region ?? null,
145
+ timezone: extras?.timezone ?? null,
146
+ screenWidth: extras?.screenWidth ?? null,
147
+ screenHeight: extras?.screenHeight ?? null,
148
+ deviceId: extras?.persistentDeviceId ?? extras?.deviceId ?? null,
149
+ isConversion: !!extras?.previousAnonymousUserId,
150
+ };
151
+ }
@@ -3,7 +3,7 @@
3
3
  * Generic service for creating/updating user documents in Firestore
4
4
  */
5
5
 
6
- import { doc, getDoc, setDoc, serverTimestamp } from "firebase/firestore";
6
+ import { doc, getDoc, setDoc, addDoc, collection, serverTimestamp } from "firebase/firestore";
7
7
  import type { User } from "firebase/auth";
8
8
  import { getFirestore } from "../../../firestore";
9
9
  import type {
@@ -16,6 +16,7 @@ import {
16
16
  buildBaseData,
17
17
  buildCreateData,
18
18
  buildUpdateData,
19
+ buildLoginHistoryEntry,
19
20
  } from "./user-document-builder.util";
20
21
 
21
22
  declare const __DEV__: boolean;
@@ -52,6 +53,16 @@ export async function ensureUserDocument(
52
53
  : buildUpdateData(baseData, allExtras);
53
54
 
54
55
  await setDoc(userRef, docData, { merge: true });
56
+
57
+ // Write login history entry (fire-and-forget)
58
+ const historyEntry = buildLoginHistoryEntry(user, allExtras);
59
+ const historyRef = collection(db, collectionName, user.uid, "loginHistory");
60
+ addDoc(historyRef, historyEntry).catch((err) => {
61
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
62
+ console.warn("[UserDocumentService] Failed to write login history:", err);
63
+ }
64
+ });
65
+
55
66
  return true;
56
67
  } catch (error) {
57
68
  if (typeof __DEV__ !== "undefined" && __DEV__) {
@@ -8,6 +8,7 @@ import { useState, useCallback, useEffect, useRef } from "react";
8
8
  import { googleOAuthService } from "../../infrastructure/services/google-oauth.service";
9
9
  import { getFirebaseAuth } from "../../infrastructure/config/FirebaseAuthClient";
10
10
  import type { GoogleOAuthConfig } from "../../infrastructure/services/google-oauth.service";
11
+ import { PLACEHOLDER_CLIENT_ID } from "../../infrastructure/services/google-auth.types";
11
12
 
12
13
  // Conditional import for expo-auth-session
13
14
  interface AuthSessionResponse {
@@ -48,8 +49,6 @@ interface SocialAuthResult {
48
49
  error?: string;
49
50
  }
50
51
 
51
- const PLACEHOLDER_CLIENT_ID = "000000000000-placeholder.apps.googleusercontent.com";
52
-
53
52
  /**
54
53
  * Hook for Google OAuth authentication
55
54
  * Requires expo-auth-session and expo-web-browser to be installed