@sudobility/auth_lib 0.0.58 → 0.0.59

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.
Files changed (2) hide show
  1. package/README.md +105 -0
  2. package/package.json +5 -5
package/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # @sudobility/auth_lib
2
+
3
+ Firebase authentication library with configurable auth initialization, resilient network clients with automatic token refresh and logout handling, admin utilities, and React hooks for auth state management. Supports both web and React Native platforms.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @sudobility/auth_lib
9
+ ```
10
+
11
+ ### Peer Dependencies
12
+
13
+ ```bash
14
+ bun add react firebase @sudobility/di @sudobility/types @tanstack/react-query
15
+ # For React Native, also:
16
+ bun add @react-native-firebase/app @react-native-firebase/auth
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```typescript
22
+ import {
23
+ initializeFirebaseAuth,
24
+ useFirebaseAuthNetworkClient,
25
+ useSiteAdmin,
26
+ getFirebaseErrorMessage,
27
+ } from '@sudobility/auth_lib';
28
+
29
+ // Initialize Firebase Auth (after Firebase app is initialized)
30
+ const { app, auth } = initializeFirebaseAuth();
31
+
32
+ // In a React component: get an auth-aware network client
33
+ const networkClient = useFirebaseAuthNetworkClient({
34
+ onLogout: () => navigate('/login'),
35
+ });
36
+
37
+ // Check if user is a site admin
38
+ const { isSiteAdmin, isLoading } = useSiteAdmin({
39
+ networkClient,
40
+ baseUrl: 'https://api.example.com',
41
+ userId: user.uid,
42
+ token: idToken,
43
+ });
44
+ ```
45
+
46
+ ## API
47
+
48
+ ### Firebase Initialization (`config/`)
49
+
50
+ | Export | Description |
51
+ |---|---|
52
+ | `initializeFirebaseAuth()` | Initialize Firebase Auth (singleton) |
53
+ | `getFirebaseApp()` | Get cached FirebaseApp instance |
54
+ | `getFirebaseAuth()` | Get cached Auth instance |
55
+ | `isFirebaseConfigured()` | Check if Firebase is initialized |
56
+
57
+ ### Hooks (`hooks/`)
58
+
59
+ | Export | Description |
60
+ |---|---|
61
+ | `useFirebaseAuthNetworkClient(options?)` | Auth-aware NetworkClient with 401 retry and 403 logout |
62
+ | `createFirebaseAuthNetworkClient(platformNetwork?, options?)` | Non-hook factory version |
63
+ | `useSiteAdmin(options)` | Check site admin status via TanStack Query |
64
+
65
+ ### Network (`network/`)
66
+
67
+ | Export | Description |
68
+ |---|---|
69
+ | `FirebaseAuthNetworkService` | Auth-aware network service (web and RN variants) |
70
+
71
+ ### Utils (`utils/`)
72
+
73
+ | Export | Description |
74
+ |---|---|
75
+ | `getFirebaseErrorMessage(code)` | Map Firebase error code to user-friendly message |
76
+ | `formatFirebaseError(error)` | Extract and map error code in one call |
77
+ | `isFirebaseAuthError(error)` | Check if error is a Firebase auth error |
78
+
79
+ ### Admin (`admin/`)
80
+
81
+ | Export | Description |
82
+ |---|---|
83
+ | `parseAdminEmails(csv)` | Parse comma-separated admin email string |
84
+ | `isAdminEmail(email, adminSet)` | Check if email is in admin set |
85
+ | `createAdminChecker(csv)` | Returns admin check function (deprecated) |
86
+
87
+ ## Dual Entry Points
88
+
89
+ - **Web**: `import` resolves to `dist/index.js` (Firebase JS SDK)
90
+ - **React Native**: `react-native` condition resolves to `dist/index.rn.js` (@react-native-firebase)
91
+
92
+ ## Development
93
+
94
+ ```bash
95
+ bun run build # Compile TypeScript to dist/
96
+ bun run dev # Watch mode build
97
+ bun test # Run tests with Vitest
98
+ bun run typecheck # Type-check without emitting
99
+ bun run lint # Lint with ESLint
100
+ bun run format # Format with Prettier
101
+ ```
102
+
103
+ ## License
104
+
105
+ BUSL-1.1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sudobility/auth_lib",
3
- "version": "0.0.58",
3
+ "version": "0.0.59",
4
4
  "description": "Firebase authentication utilities with token refresh handling",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -37,8 +37,8 @@
37
37
  "firebase": "^12.7.0",
38
38
  "@react-native-firebase/app": ">=18.0.0",
39
39
  "@react-native-firebase/auth": ">=18.0.0",
40
- "@sudobility/di": "^1.5.43",
41
- "@sudobility/types": "^1.9.55",
40
+ "@sudobility/di": "^1.5.45",
41
+ "@sudobility/types": "^1.9.57",
42
42
  "@tanstack/react-query": "^5.0.0"
43
43
  },
44
44
  "peerDependenciesMeta": {
@@ -53,8 +53,8 @@
53
53
  }
54
54
  },
55
55
  "devDependencies": {
56
- "@sudobility/di": "^1.5.43",
57
- "@sudobility/types": "^1.9.55",
56
+ "@sudobility/di": "^1.5.45",
57
+ "@sudobility/types": "^1.9.57",
58
58
  "@tanstack/react-query": "^5.80.7",
59
59
  "@types/node": "^22.0.0",
60
60
  "vitest": "^4.0.4",