@umituz/react-native-firebase 1.13.105 → 1.13.106

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": "1.13.105",
3
+ "version": "1.13.106",
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",
@@ -10,8 +10,8 @@ import {
10
10
  type UserCredential,
11
11
  } from "firebase/auth";
12
12
  import * as AppleAuthentication from "expo-apple-authentication";
13
- import * as Crypto from "expo-crypto";
14
13
  import { Platform } from "react-native";
14
+ import { generateNonce, hashNonce } from "./crypto.util";
15
15
 
16
16
  export interface AppleAuthResult {
17
17
  success: boolean;
@@ -40,11 +40,8 @@ export class AppleAuthService {
40
40
  };
41
41
  }
42
42
 
43
- const nonce = await this.generateNonce();
44
- const hashedNonce = await Crypto.digestStringAsync(
45
- Crypto.CryptoDigestAlgorithm.SHA256,
46
- nonce,
47
- );
43
+ const nonce = await generateNonce();
44
+ const hashedNonce = await hashNonce(nonce);
48
45
 
49
46
  const appleCredential = await AppleAuthentication.signInAsync({
50
47
  requestedScopes: [
@@ -86,16 +83,6 @@ export class AppleAuthService {
86
83
  }
87
84
  }
88
85
 
89
- private async generateNonce(length: number = 32): Promise<string> {
90
- const randomBytes = await Crypto.getRandomBytesAsync(length);
91
- const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
92
- let result = "";
93
- for (let i = 0; i < randomBytes.length; i++) {
94
- const byte = randomBytes[i];
95
- if (byte !== undefined) result += chars.charAt(byte % chars.length);
96
- }
97
- return result;
98
- }
99
86
  }
100
87
 
101
88
  export const appleAuthService = new AppleAuthService();
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Crypto Utilities
3
+ * Shared cryptographic helpers for auth services
4
+ */
5
+
6
+ import * as Crypto from "expo-crypto";
7
+
8
+ const NONCE_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
9
+
10
+ export async function generateNonce(length: number = 32): Promise<string> {
11
+ const bytes = await Crypto.getRandomBytesAsync(length);
12
+ return Array.from(bytes).map(b => NONCE_CHARS.charAt(b % NONCE_CHARS.length)).join("");
13
+ }
14
+
15
+ export async function hashNonce(nonce: string): Promise<string> {
16
+ return Crypto.digestStringAsync(Crypto.CryptoDigestAlgorithm.SHA256, nonce);
17
+ }
@@ -11,8 +11,8 @@ import {
11
11
  type User,
12
12
  } from "firebase/auth";
13
13
  import * as AppleAuthentication from "expo-apple-authentication";
14
- import * as Crypto from "expo-crypto";
15
14
  import { Platform } from "react-native";
15
+ import { generateNonce, hashNonce } from "./crypto.util";
16
16
  import type {
17
17
  ReauthenticationResult,
18
18
  AuthProviderType,
@@ -54,12 +54,6 @@ export async function reauthenticateWithPassword(user: User, pass: string): Prom
54
54
  }
55
55
  }
56
56
 
57
- async function generateNonce(len: number = 32): Promise<string> {
58
- const bytes = await Crypto.getRandomBytesAsync(len);
59
- const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
60
- return Array.from(bytes).map(b => chars.charAt(b % chars.length)).join("");
61
- }
62
-
63
57
  export async function getAppleReauthCredential(): Promise<ReauthCredentialResult> {
64
58
  if (Platform.OS !== "ios") return { success: false, error: { code: "auth/ios-only", message: "iOS only" } };
65
59
  try {
@@ -67,7 +61,7 @@ export async function getAppleReauthCredential(): Promise<ReauthCredentialResult
67
61
  return { success: false, error: { code: "auth/unavailable", message: "Unavailable" } };
68
62
 
69
63
  const nonce = await generateNonce();
70
- const hashed = await Crypto.digestStringAsync(Crypto.CryptoDigestAlgorithm.SHA256, nonce);
64
+ const hashed = await hashNonce(nonce);
71
65
  const apple = await AppleAuthentication.signInAsync({
72
66
  requestedScopes: [AppleAuthentication.AppleAuthenticationScope.FULL_NAME, AppleAuthentication.AppleAuthenticationScope.EMAIL],
73
67
  nonce: hashed,
@@ -10,7 +10,7 @@ export function isoToTimestamp(isoString: string): Timestamp {
10
10
  /**
11
11
  * Convert Firestore Timestamp to ISO string
12
12
  */
13
- export function timestampToISO(timestamp: Timestamp): string {
13
+ export function timestampToISO(timestamp: Timestamp | null | undefined): string {
14
14
  if (!timestamp) return new Date().toISOString();
15
15
  return timestamp.toDate().toISOString();
16
16
  }
@@ -18,7 +18,7 @@ export function timestampToISO(timestamp: Timestamp): string {
18
18
  /**
19
19
  * Convert Firestore Timestamp to Date
20
20
  */
21
- export function timestampToDate(timestamp: Timestamp): Date {
21
+ export function timestampToDate(timestamp: Timestamp | null | undefined): Date {
22
22
  if (!timestamp) return new Date();
23
23
  return timestamp.toDate();
24
24
  }
@@ -3,8 +3,8 @@
3
3
  * Handles single and batch deletion from Firebase Storage
4
4
  */
5
5
 
6
- import { getStorage, ref, deleteObject } from "firebase/storage";
7
- import { getFirebaseApp } from "../infrastructure/config/FirebaseClient";
6
+ import { ref, deleteObject } from "firebase/storage";
7
+ import { getStorageInstance } from "./storage-instance";
8
8
  import type { DeleteResult } from "./types";
9
9
 
10
10
  declare const __DEV__: boolean;
@@ -39,11 +39,6 @@ function extractStoragePath(downloadUrl: string): string | null {
39
39
  }
40
40
  }
41
41
 
42
- function getStorageInstance() {
43
- const app = getFirebaseApp();
44
- return app ? getStorage(app) : null;
45
- }
46
-
47
42
  /**
48
43
  * Delete image from Firebase Storage
49
44
  * Accepts either a download URL or storage path
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Shared Firebase Storage instance getter
3
+ */
4
+
5
+ import { getStorage } from "firebase/storage";
6
+ import { getFirebaseApp } from "../infrastructure/config/FirebaseClient";
7
+
8
+ export function getStorageInstance() {
9
+ const app = getFirebaseApp();
10
+ return app ? getStorage(app) : null;
11
+ }
@@ -4,13 +4,12 @@
4
4
  */
5
5
 
6
6
  import {
7
- getStorage,
8
7
  ref,
9
8
  uploadBytes,
10
9
  getDownloadURL,
11
10
  type UploadMetadata,
12
11
  } from "firebase/storage";
13
- import { getFirebaseApp } from "../infrastructure/config/FirebaseClient";
12
+ import { getStorageInstance } from "./storage-instance";
14
13
  import type { UploadResult, UploadOptions } from "./types";
15
14
 
16
15
  declare const __DEV__: boolean;
@@ -35,11 +34,6 @@ function ensureDataUrl(base64: string, mimeType: string): string {
35
34
  return `data:${mimeType};base64,${base64}`;
36
35
  }
37
36
 
38
- function getStorageInstance() {
39
- const app = getFirebaseApp();
40
- return app ? getStorage(app) : null;
41
- }
42
-
43
37
  /**
44
38
  * Upload base64 image to Firebase Storage
45
39
  */