@sudobility/auth_lib 0.0.16 → 0.0.18
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/admin/index.d.ts +0 -7
- package/dist/admin/index.d.ts.map +1 -1
- package/dist/admin/index.js +1 -7
- package/dist/admin/index.js.map +1 -0
- package/dist/config/firebase-init.d.ts +0 -31
- package/dist/config/firebase-init.d.ts.map +1 -1
- package/dist/config/firebase-init.js +13 -38
- package/dist/config/firebase-init.js.map +1 -0
- package/dist/config/firebase-init.rn.d.ts +10 -0
- package/dist/config/firebase-init.rn.d.ts.map +1 -0
- package/dist/config/firebase-init.rn.js +62 -0
- package/dist/config/firebase-init.rn.js.map +1 -0
- package/dist/config/index.d.ts +0 -3
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -3
- package/dist/config/index.js.map +1 -0
- package/dist/config/types.d.ts +0 -18
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js +1 -3
- package/dist/config/types.js.map +1 -0
- package/dist/hooks/index.d.ts +0 -3
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -3
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useFirebaseAuthNetworkClient.d.ts +0 -19
- package/dist/hooks/useFirebaseAuthNetworkClient.d.ts.map +1 -1
- package/dist/hooks/useFirebaseAuthNetworkClient.js +27 -49
- package/dist/hooks/useFirebaseAuthNetworkClient.js.map +1 -0
- package/dist/hooks/useSiteAdmin.d.ts +0 -46
- package/dist/hooks/useSiteAdmin.d.ts.map +1 -1
- package/dist/hooks/useSiteAdmin.js +2 -33
- package/dist/hooks/useSiteAdmin.js.map +1 -0
- package/dist/index.d.ts +0 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -13
- package/dist/index.js.map +1 -0
- package/dist/index.rn.d.ts +8 -0
- package/dist/index.rn.d.ts.map +1 -0
- package/dist/index.rn.js +7 -0
- package/dist/index.rn.js.map +1 -0
- package/dist/network/FirebaseAuthNetworkService.d.ts +1 -17
- package/dist/network/FirebaseAuthNetworkService.d.ts.map +1 -1
- package/dist/network/FirebaseAuthNetworkService.js +4 -34
- package/dist/network/FirebaseAuthNetworkService.js.map +1 -0
- package/dist/network/FirebaseAuthNetworkService.rn.d.ts +11 -0
- package/dist/network/FirebaseAuthNetworkService.rn.d.ts.map +1 -0
- package/dist/network/FirebaseAuthNetworkService.rn.js +58 -0
- package/dist/network/FirebaseAuthNetworkService.rn.js.map +1 -0
- package/dist/network/index.d.ts +0 -3
- package/dist/network/index.d.ts.map +1 -1
- package/dist/network/index.js +1 -3
- package/dist/network/index.js.map +1 -0
- package/dist/utils/firebase-errors.d.ts +0 -27
- package/dist/utils/firebase-errors.d.ts.map +1 -1
- package/dist/utils/firebase-errors.js +1 -28
- package/dist/utils/firebase-errors.js.map +1 -0
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -3
- package/dist/utils/index.js.map +1 -0
- package/package.json +21 -3
package/dist/admin/index.d.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Admin utilities exports
|
|
3
|
-
*
|
|
4
|
-
* Re-exports admin utilities from @sudobility/types for backwards compatibility.
|
|
5
|
-
* These utilities are now defined in @sudobility/types to be shared between
|
|
6
|
-
* frontend (auth_lib) and backend (auth_service) packages.
|
|
7
|
-
*/
|
|
8
1
|
export { parseAdminEmails, isAdminEmail, createAdminChecker, } from '@sudobility/types';
|
|
9
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,GACnB,MAAM,mBAAmB,CAAC"}
|
package/dist/admin/index.js
CHANGED
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Admin utilities exports
|
|
3
|
-
*
|
|
4
|
-
* Re-exports admin utilities from @sudobility/types for backwards compatibility.
|
|
5
|
-
* These utilities are now defined in @sudobility/types to be shared between
|
|
6
|
-
* frontend (auth_lib) and backend (auth_service) packages.
|
|
7
|
-
*/
|
|
8
1
|
export { parseAdminEmails, isAdminEmail, createAdminChecker, } from '@sudobility/types';
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,GACnB,MAAM,mBAAmB,CAAC"}
|
|
@@ -1,40 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Configurable Firebase initialization
|
|
3
|
-
*/
|
|
4
1
|
import { type FirebaseApp } from 'firebase/app';
|
|
5
2
|
import { type Auth } from 'firebase/auth';
|
|
6
3
|
import type { FirebaseConfig, FirebaseInitOptions, FirebaseInitResult } from './types';
|
|
7
|
-
/**
|
|
8
|
-
* Check if Firebase is configured with the required fields
|
|
9
|
-
*/
|
|
10
4
|
export declare function isFirebaseConfigured(): boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Initialize Firebase Auth with the provided configuration.
|
|
13
|
-
* This should be called once at app startup (e.g., in main.tsx).
|
|
14
|
-
*
|
|
15
|
-
* @param options - Firebase initialization options
|
|
16
|
-
* @returns Firebase app and auth instances
|
|
17
|
-
* @throws Error if Firebase is already initialized with different config
|
|
18
|
-
*/
|
|
19
5
|
export declare function initializeFirebaseAuth(options: FirebaseInitOptions): FirebaseInitResult;
|
|
20
|
-
/**
|
|
21
|
-
* Get the Firebase app instance.
|
|
22
|
-
* Must call initializeFirebaseAuth() first.
|
|
23
|
-
*
|
|
24
|
-
* @returns Firebase app instance or null if not initialized
|
|
25
|
-
*/
|
|
26
6
|
export declare function getFirebaseApp(): FirebaseApp | null;
|
|
27
|
-
/**
|
|
28
|
-
* Get the Firebase auth instance.
|
|
29
|
-
* Must call initializeFirebaseAuth() first.
|
|
30
|
-
*
|
|
31
|
-
* @returns Firebase auth instance or null if not initialized
|
|
32
|
-
*/
|
|
33
7
|
export declare function getFirebaseAuth(): Auth | null;
|
|
34
|
-
/**
|
|
35
|
-
* Get the current Firebase configuration.
|
|
36
|
-
*
|
|
37
|
-
* @returns Firebase config or null if not initialized
|
|
38
|
-
*/
|
|
39
8
|
export declare function getFirebaseConfig(): FirebaseConfig | null;
|
|
40
9
|
//# sourceMappingURL=firebase-init.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firebase-init.d.ts","sourceRoot":"","sources":["../../src/config/firebase-init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"firebase-init.d.ts","sourceRoot":"","sources":["../../src/config/firebase-init.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,WAAW,EAAkC,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,KAAK,IAAI,EAA+B,MAAM,eAAe,CAAC;AAEvE,OAAO,KAAK,EACV,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAUjB,wBAAgB,oBAAoB,IAAI,OAAO,CAS9C;AAUD,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,mBAAmB,GAC3B,kBAAkB,CAwCpB;AAQD,wBAAgB,cAAc,IAAI,WAAW,GAAG,IAAI,CAEnD;AAQD,wBAAgB,eAAe,IAAI,IAAI,GAAG,IAAI,CAE7C;AAOD,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,IAAI,CAEzD"}
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Configurable Firebase initialization
|
|
3
|
-
*/
|
|
4
1
|
import { getApp, getApps, initializeApp } from 'firebase/app';
|
|
5
|
-
import { getAuth } from 'firebase/auth';
|
|
6
|
-
|
|
2
|
+
import { getAuth, onAuthStateChanged } from 'firebase/auth';
|
|
3
|
+
import { getFirebaseService } from '@sudobility/di';
|
|
7
4
|
let firebaseApp = null;
|
|
8
5
|
let firebaseAuth = null;
|
|
9
6
|
let firebaseConfig = null;
|
|
10
|
-
/**
|
|
11
|
-
* Check if Firebase is configured with the required fields
|
|
12
|
-
*/
|
|
13
7
|
export function isFirebaseConfigured() {
|
|
14
8
|
if (!firebaseConfig)
|
|
15
9
|
return false;
|
|
@@ -21,55 +15,36 @@ export function isFirebaseConfigured() {
|
|
|
21
15
|
];
|
|
22
16
|
return requiredFields.every(field => !!firebaseConfig?.[field]);
|
|
23
17
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Initialize Firebase Auth with the provided configuration.
|
|
26
|
-
* This should be called once at app startup (e.g., in main.tsx).
|
|
27
|
-
*
|
|
28
|
-
* @param options - Firebase initialization options
|
|
29
|
-
* @returns Firebase app and auth instances
|
|
30
|
-
* @throws Error if Firebase is already initialized with different config
|
|
31
|
-
*/
|
|
32
18
|
export function initializeFirebaseAuth(options) {
|
|
33
19
|
const { config } = options;
|
|
34
|
-
// Store the config
|
|
35
20
|
firebaseConfig = config;
|
|
36
|
-
// Check if already initialized
|
|
37
21
|
if (firebaseApp && firebaseAuth) {
|
|
38
22
|
return { app: firebaseApp, auth: firebaseAuth };
|
|
39
23
|
}
|
|
40
|
-
// Validate configuration
|
|
41
24
|
if (!isFirebaseConfigured()) {
|
|
42
25
|
throw new Error('[auth_lib] Firebase configuration is incomplete. Required fields: apiKey, authDomain, projectId, appId');
|
|
43
26
|
}
|
|
44
|
-
// Initialize Firebase app (avoid duplicate initialization)
|
|
45
27
|
firebaseApp = getApps().length === 0 ? initializeApp(config) : getApp();
|
|
46
|
-
// Initialize Firebase Auth
|
|
47
28
|
firebaseAuth = getAuth(firebaseApp);
|
|
29
|
+
onAuthStateChanged(firebaseAuth, user => {
|
|
30
|
+
try {
|
|
31
|
+
const firebaseService = getFirebaseService();
|
|
32
|
+
if (user) {
|
|
33
|
+
firebaseService.analytics.setUserId(user.uid);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
}
|
|
38
|
+
});
|
|
48
39
|
return { app: firebaseApp, auth: firebaseAuth };
|
|
49
40
|
}
|
|
50
|
-
/**
|
|
51
|
-
* Get the Firebase app instance.
|
|
52
|
-
* Must call initializeFirebaseAuth() first.
|
|
53
|
-
*
|
|
54
|
-
* @returns Firebase app instance or null if not initialized
|
|
55
|
-
*/
|
|
56
41
|
export function getFirebaseApp() {
|
|
57
42
|
return firebaseApp;
|
|
58
43
|
}
|
|
59
|
-
/**
|
|
60
|
-
* Get the Firebase auth instance.
|
|
61
|
-
* Must call initializeFirebaseAuth() first.
|
|
62
|
-
*
|
|
63
|
-
* @returns Firebase auth instance or null if not initialized
|
|
64
|
-
*/
|
|
65
44
|
export function getFirebaseAuth() {
|
|
66
45
|
return firebaseAuth;
|
|
67
46
|
}
|
|
68
|
-
/**
|
|
69
|
-
* Get the current Firebase configuration.
|
|
70
|
-
*
|
|
71
|
-
* @returns Firebase config or null if not initialized
|
|
72
|
-
*/
|
|
73
47
|
export function getFirebaseConfig() {
|
|
74
48
|
return firebaseConfig;
|
|
75
49
|
}
|
|
50
|
+
//# sourceMappingURL=firebase-init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase-init.js","sourceRoot":"","sources":["../../src/config/firebase-init.ts"],"names":[],"mappings":"AAIA,OAAO,EAAoB,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAa,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAQpD,IAAI,WAAW,GAAuB,IAAI,CA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AE,IAAI,EAAE,YAAY,EAAE,CAAC;AAClD,CAAC;AAQD,MAAM,UAAU,cAAc;IAC5B,OAAO,WAAW,CAAC;AACrB,CAAC;AAQD,MAAM,UAAU,eAAe;IAC7B,OAAO,YAAY,CAAC;AACtB,CAAC;AAOD,MAAM,UAAU,iBAAiB;IAC/B,OAAO,cAAc,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FirebaseInitOptions, FirebaseInitResult } from './types.js';
|
|
2
|
+
type RNFirebaseAuth = any;
|
|
3
|
+
type RNFirebaseApp = any;
|
|
4
|
+
export declare function isFirebaseConfigured(): boolean;
|
|
5
|
+
export declare function initializeFirebaseAuth(_options?: FirebaseInitOptions): FirebaseInitResult;
|
|
6
|
+
export declare function getFirebaseApp(): RNFirebaseApp | null;
|
|
7
|
+
export declare function getFirebaseAuth(): RNFirebaseAuth | null;
|
|
8
|
+
export declare function getFirebaseConfig(): null;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=firebase-init.rn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase-init.rn.d.ts","sourceRoot":"","sources":["../../src/config/firebase-init.rn.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAI1E,KAAK,cAAc,GAAG,GAAG,CAAC;AAE1B,KAAK,aAAa,GAAG,GAAG,CAAC;AA0CzB,wBAAgB,oBAAoB,IAAI,OAAO,CAE9C;AAUD,wBAAgB,sBAAsB,CACpC,QAAQ,CAAC,EAAE,mBAAmB,GAC7B,kBAAkB,CA+BpB;AAMD,wBAAgB,cAAc,IAAI,aAAa,GAAG,IAAI,CAErD;AAMD,wBAAgB,eAAe,IAAI,cAAc,GAAG,IAAI,CAEvD;AAMD,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { getFirebaseService } from '@sudobility/di';
|
|
2
|
+
let firebaseAuth = null;
|
|
3
|
+
let firebaseApp = null;
|
|
4
|
+
let initialized = false;
|
|
5
|
+
function getAuthModule() {
|
|
6
|
+
if (!firebaseAuth) {
|
|
7
|
+
try {
|
|
8
|
+
const authModule = require('@react-native-firebase/auth');
|
|
9
|
+
firebaseAuth = authModule.default ? authModule.default() : authModule();
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
console.warn('[auth_lib] @react-native-firebase/auth not available:', e);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return firebaseAuth;
|
|
16
|
+
}
|
|
17
|
+
function getAppModule() {
|
|
18
|
+
if (!firebaseApp) {
|
|
19
|
+
try {
|
|
20
|
+
const appModule = require('@react-native-firebase/app');
|
|
21
|
+
firebaseApp = appModule.default ? appModule.default() : appModule;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
console.warn('[auth_lib] @react-native-firebase/app not available:', e);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return firebaseApp;
|
|
28
|
+
}
|
|
29
|
+
export function isFirebaseConfigured() {
|
|
30
|
+
return getAppModule() !== null;
|
|
31
|
+
}
|
|
32
|
+
export function initializeFirebaseAuth(_options) {
|
|
33
|
+
const app = getAppModule();
|
|
34
|
+
const auth = getAuthModule();
|
|
35
|
+
if (!app || !auth) {
|
|
36
|
+
throw new Error('[auth_lib] React Native Firebase is not available. Make sure @react-native-firebase/app and @react-native-firebase/auth are installed.');
|
|
37
|
+
}
|
|
38
|
+
if (!initialized) {
|
|
39
|
+
auth.onAuthStateChanged((user) => {
|
|
40
|
+
try {
|
|
41
|
+
const firebaseService = getFirebaseService();
|
|
42
|
+
if (user) {
|
|
43
|
+
firebaseService.analytics.setUserId(user.uid);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
initialized = true;
|
|
50
|
+
}
|
|
51
|
+
return { app, auth };
|
|
52
|
+
}
|
|
53
|
+
export function getFirebaseApp() {
|
|
54
|
+
return getAppModule();
|
|
55
|
+
}
|
|
56
|
+
export function getFirebaseAuth() {
|
|
57
|
+
return getAuthModule();
|
|
58
|
+
}
|
|
59
|
+
export function getFirebaseConfig() {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=firebase-init.rn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase-init.rn.js","sourceRoot":"","sources":["../../src/config/firebase-init.rn.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAUpD,IAAI,YAAY,GAA0B,IAAI,CAAC;AAC/C,IAAI,WAAW,GAAyB,IAAI,CAAC;AAC7C,IAAI,WAAW,GAAG,KAAK,CAAC;AAKxB,SAAS,aAAa;IACpB,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,IAAI,CAAC;YAEH,MAAM,UAAU,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;YAC1D,YAAY,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;QAC1E,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,IAAI,CAAC,uDAAuD,EAAE,CAAC,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAKD,SAAS,YAAY;IACnB,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,IAAI,CAAC;YAEH,MAAM,SAAS,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;YACxD,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QACpE,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;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, getFirebaseAuth, getFirebaseConfig, isFirebaseConfigured, } from './firebase-init';
|
|
5
2
|
export type { FirebaseConfig, FirebaseInitOptions, FirebaseInitResult, FirebaseAuthNetworkClientOptions, } from './types';
|
|
6
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,gCAAgC,GACjC,MAAM,SAAS,CAAC"}
|
package/dist/config/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC"}
|
package/dist/config/types.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Type definitions for auth_lib
|
|
3
|
-
*/
|
|
4
1
|
import type { Auth } from 'firebase/auth';
|
|
5
2
|
import type { FirebaseApp } from 'firebase/app';
|
|
6
|
-
/**
|
|
7
|
-
* Firebase configuration object
|
|
8
|
-
*/
|
|
9
3
|
export interface FirebaseConfig {
|
|
10
4
|
apiKey: string;
|
|
11
5
|
authDomain: string;
|
|
@@ -15,27 +9,15 @@ export interface FirebaseConfig {
|
|
|
15
9
|
appId: string;
|
|
16
10
|
measurementId?: string;
|
|
17
11
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Options for initializing Firebase Auth
|
|
20
|
-
*/
|
|
21
12
|
export interface FirebaseInitOptions {
|
|
22
|
-
/** Firebase configuration */
|
|
23
13
|
config: FirebaseConfig;
|
|
24
14
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Result of Firebase initialization
|
|
27
|
-
*/
|
|
28
15
|
export interface FirebaseInitResult {
|
|
29
16
|
app: FirebaseApp;
|
|
30
17
|
auth: Auth;
|
|
31
18
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Options for the Firebase Auth network client hook
|
|
34
|
-
*/
|
|
35
19
|
export interface FirebaseAuthNetworkClientOptions {
|
|
36
|
-
/** Callback when user is logged out due to 403 */
|
|
37
20
|
onLogout?: () => void;
|
|
38
|
-
/** Callback when token refresh fails */
|
|
39
21
|
onTokenRefreshFailed?: (error: unknown) => void;
|
|
40
22
|
}
|
|
41
23
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAKhD,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAKD,MAAM,WAAW,mBAAmB;IAElC,MAAM,EAAE,cAAc,CAAC;CACxB;AAKD,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,WAAW,CAAC;IACjB,IAAI,EAAE,IAAI,CAAC;CACZ;AAKD,MAAM,WAAW,gCAAgC;IAE/C,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IAEtB,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACjD"}
|
package/dist/config/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":""}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Hooks exports
|
|
3
|
-
*/
|
|
4
1
|
export { useFirebaseAuthNetworkClient, createFirebaseAuthNetworkClient, } from './useFirebaseAuthNetworkClient';
|
|
5
2
|
export { useSiteAdmin, siteAdminQueryKey, type UseSiteAdminOptions, type UseSiteAdminResult, type UserInfoResponse, } from './useSiteAdmin';
|
|
6
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,4BAA4B,EAC5B,+BAA+B,GAChC,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,GACtB,MAAM,gBAAgB,CAAC"}
|
package/dist/hooks/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,4BAA4B,EAC5B,+BAA+B,GAChC,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,YAAY,EACZ,iBAAiB,GAIlB,MAAM,gBAAgB,CAAC"}
|
|
@@ -1,26 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Hook to provide a resilient network client with automatic token refresh and logout handling.
|
|
3
|
-
*
|
|
4
|
-
* - On 401 (Unauthorized): Force refresh Firebase token and retry once
|
|
5
|
-
* - On 403 (Forbidden): Log the user out
|
|
6
|
-
*/
|
|
7
1
|
import type { NetworkClient } from '@sudobility/types';
|
|
8
2
|
import type { FirebaseAuthNetworkClientOptions } from '../config/types';
|
|
9
|
-
/**
|
|
10
|
-
* Create a network client adapter that wraps a platform network
|
|
11
|
-
* with 401 retry and 403 logout handling.
|
|
12
|
-
*
|
|
13
|
-
* @param platformNetwork - The underlying network service to wrap (optional, defaults to getNetworkService())
|
|
14
|
-
* @param options - Optional callbacks for logout and token refresh failure
|
|
15
|
-
*/
|
|
16
3
|
export declare function createFirebaseAuthNetworkClient(platformNetwork?: {
|
|
17
4
|
request: (url: string, options?: RequestInit) => Promise<Response>;
|
|
18
5
|
}, options?: FirebaseAuthNetworkClientOptions): NetworkClient;
|
|
19
|
-
/**
|
|
20
|
-
* Hook to get a Firebase Auth network client with automatic 401 retry and 403 logout.
|
|
21
|
-
*
|
|
22
|
-
* @param options - Optional callbacks for logout and token refresh failure
|
|
23
|
-
* @returns NetworkClient instance
|
|
24
|
-
*/
|
|
25
6
|
export declare function useFirebaseAuthNetworkClient(options?: FirebaseAuthNetworkClientOptions): NetworkClient;
|
|
26
7
|
//# sourceMappingURL=useFirebaseAuthNetworkClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFirebaseAuthNetworkClient.d.ts","sourceRoot":"","sources":["../../src/hooks/useFirebaseAuthNetworkClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFirebaseAuthNetworkClient.d.ts","sourceRoot":"","sources":["../../src/hooks/useFirebaseAuthNetworkClient.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,aAAa,EAId,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,iBAAiB,CAAC;AA2CxE,wBAAgB,+BAA+B,CAC7C,eAAe,CAAC,EAAE;IAChB,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CACpE,EACD,OAAO,CAAC,EAAE,gCAAgC,GACzC,aAAa,CA6If;AAQD,wBAAgB,4BAA4B,CAC1C,OAAO,CAAC,EAAE,gCAAgC,GACzC,aAAa,CAKf"}
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Hook to provide a resilient network client with automatic token refresh and logout handling.
|
|
3
|
-
*
|
|
4
|
-
* - On 401 (Unauthorized): Force refresh Firebase token and retry once
|
|
5
|
-
* - On 403 (Forbidden): Log the user out
|
|
6
|
-
*/
|
|
7
1
|
import { useMemo } from 'react';
|
|
8
2
|
import { getNetworkService } from '@sudobility/di';
|
|
9
3
|
import { signOut } from 'firebase/auth';
|
|
10
4
|
import { getFirebaseAuth } from '../config/firebase-init';
|
|
11
|
-
/**
|
|
12
|
-
* Get a fresh Firebase ID token with force refresh.
|
|
13
|
-
* Returns empty string if not authenticated.
|
|
14
|
-
*/
|
|
15
5
|
async function getAuthToken(forceRefresh = false) {
|
|
16
6
|
const auth = getFirebaseAuth();
|
|
17
7
|
const user = auth?.currentUser;
|
|
@@ -25,9 +15,6 @@ async function getAuthToken(forceRefresh = false) {
|
|
|
25
15
|
return '';
|
|
26
16
|
}
|
|
27
17
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Log the user out via Firebase.
|
|
30
|
-
*/
|
|
31
18
|
async function logoutUser(onLogout) {
|
|
32
19
|
const auth = getFirebaseAuth();
|
|
33
20
|
if (!auth)
|
|
@@ -40,13 +27,6 @@ async function logoutUser(onLogout) {
|
|
|
40
27
|
console.error('[useFirebaseAuthNetworkClient] Failed to sign out:', err);
|
|
41
28
|
}
|
|
42
29
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Create a network client adapter that wraps a platform network
|
|
45
|
-
* with 401 retry and 403 logout handling.
|
|
46
|
-
*
|
|
47
|
-
* @param platformNetwork - The underlying network service to wrap (optional, defaults to getNetworkService())
|
|
48
|
-
* @param options - Optional callbacks for logout and token refresh failure
|
|
49
|
-
*/
|
|
50
30
|
export function createFirebaseAuthNetworkClient(platformNetwork, options) {
|
|
51
31
|
const network = platformNetwork ?? getNetworkService();
|
|
52
32
|
const parseResponse = async (response) => {
|
|
@@ -57,7 +37,6 @@ export function createFirebaseAuthNetworkClient(platformNetwork, options) {
|
|
|
57
37
|
data = (await response.json());
|
|
58
38
|
}
|
|
59
39
|
catch {
|
|
60
|
-
// JSON parse failed, leave data undefined
|
|
61
40
|
}
|
|
62
41
|
}
|
|
63
42
|
const headers = {};
|
|
@@ -74,14 +53,8 @@ export function createFirebaseAuthNetworkClient(platformNetwork, options) {
|
|
|
74
53
|
timestamp: new Date().toISOString(),
|
|
75
54
|
};
|
|
76
55
|
};
|
|
77
|
-
/**
|
|
78
|
-
* Execute request with retry logic:
|
|
79
|
-
* - On 401: Force refresh token and retry once
|
|
80
|
-
* - On 403: Log user out (no retry)
|
|
81
|
-
*/
|
|
82
56
|
const executeWithRetry = async (url, requestInit) => {
|
|
83
57
|
const response = await network.request(url, requestInit);
|
|
84
|
-
// On 401, get fresh token and retry once
|
|
85
58
|
if (response.status === 401) {
|
|
86
59
|
const freshToken = await getAuthToken(true);
|
|
87
60
|
if (freshToken) {
|
|
@@ -96,15 +69,12 @@ export function createFirebaseAuthNetworkClient(platformNetwork, options) {
|
|
|
96
69
|
return parseResponse(retryResponse);
|
|
97
70
|
}
|
|
98
71
|
else {
|
|
99
|
-
// Token refresh failed
|
|
100
72
|
options?.onTokenRefreshFailed?.(new Error('Failed to refresh token'));
|
|
101
73
|
}
|
|
102
74
|
}
|
|
103
|
-
// On 403, log the user out
|
|
104
75
|
if (response.status === 403) {
|
|
105
76
|
console.warn('[useFirebaseAuthNetworkClient] 403 Forbidden - logging user out');
|
|
106
77
|
await logoutUser(options?.onLogout);
|
|
107
|
-
// Return the original response so the UI can handle it
|
|
108
78
|
}
|
|
109
79
|
return parseResponse(response);
|
|
110
80
|
};
|
|
@@ -112,54 +82,62 @@ export function createFirebaseAuthNetworkClient(platformNetwork, options) {
|
|
|
112
82
|
async request(url, reqOptions) {
|
|
113
83
|
const requestInit = {
|
|
114
84
|
method: reqOptions?.method ?? 'GET',
|
|
115
|
-
headers: reqOptions?.headers ?? undefined,
|
|
116
|
-
body: reqOptions?.body ?? undefined,
|
|
117
|
-
signal: reqOptions?.signal ?? undefined,
|
|
118
85
|
};
|
|
86
|
+
if (reqOptions?.headers)
|
|
87
|
+
requestInit.headers = reqOptions.headers;
|
|
88
|
+
if (reqOptions?.body)
|
|
89
|
+
requestInit.body = reqOptions.body;
|
|
90
|
+
if (reqOptions?.signal)
|
|
91
|
+
requestInit.signal = reqOptions.signal;
|
|
119
92
|
return executeWithRetry(url, requestInit);
|
|
120
93
|
},
|
|
121
94
|
async get(url, reqOptions) {
|
|
122
95
|
const requestInit = {
|
|
123
96
|
method: 'GET',
|
|
124
|
-
headers: reqOptions?.headers ?? undefined,
|
|
125
|
-
signal: reqOptions?.signal ?? undefined,
|
|
126
97
|
};
|
|
98
|
+
if (reqOptions?.headers)
|
|
99
|
+
requestInit.headers = reqOptions.headers;
|
|
100
|
+
if (reqOptions?.signal)
|
|
101
|
+
requestInit.signal = reqOptions.signal;
|
|
127
102
|
return executeWithRetry(url, requestInit);
|
|
128
103
|
},
|
|
129
104
|
async post(url, body, reqOptions) {
|
|
130
105
|
const requestInit = {
|
|
131
106
|
method: 'POST',
|
|
132
|
-
headers: reqOptions?.headers ?? undefined,
|
|
133
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
134
|
-
signal: reqOptions?.signal ?? undefined,
|
|
135
107
|
};
|
|
108
|
+
if (reqOptions?.headers)
|
|
109
|
+
requestInit.headers = reqOptions.headers;
|
|
110
|
+
if (body)
|
|
111
|
+
requestInit.body = JSON.stringify(body);
|
|
112
|
+
if (reqOptions?.signal)
|
|
113
|
+
requestInit.signal = reqOptions.signal;
|
|
136
114
|
return executeWithRetry(url, requestInit);
|
|
137
115
|
},
|
|
138
116
|
async put(url, body, reqOptions) {
|
|
139
117
|
const requestInit = {
|
|
140
118
|
method: 'PUT',
|
|
141
|
-
headers: reqOptions?.headers ?? undefined,
|
|
142
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
143
|
-
signal: reqOptions?.signal ?? undefined,
|
|
144
119
|
};
|
|
120
|
+
if (reqOptions?.headers)
|
|
121
|
+
requestInit.headers = reqOptions.headers;
|
|
122
|
+
if (body)
|
|
123
|
+
requestInit.body = JSON.stringify(body);
|
|
124
|
+
if (reqOptions?.signal)
|
|
125
|
+
requestInit.signal = reqOptions.signal;
|
|
145
126
|
return executeWithRetry(url, requestInit);
|
|
146
127
|
},
|
|
147
128
|
async delete(url, reqOptions) {
|
|
148
129
|
const requestInit = {
|
|
149
130
|
method: 'DELETE',
|
|
150
|
-
headers: reqOptions?.headers ?? undefined,
|
|
151
|
-
signal: reqOptions?.signal ?? undefined,
|
|
152
131
|
};
|
|
132
|
+
if (reqOptions?.headers)
|
|
133
|
+
requestInit.headers = reqOptions.headers;
|
|
134
|
+
if (reqOptions?.signal)
|
|
135
|
+
requestInit.signal = reqOptions.signal;
|
|
153
136
|
return executeWithRetry(url, requestInit);
|
|
154
137
|
},
|
|
155
138
|
};
|
|
156
139
|
}
|
|
157
|
-
/**
|
|
158
|
-
* Hook to get a Firebase Auth network client with automatic 401 retry and 403 logout.
|
|
159
|
-
*
|
|
160
|
-
* @param options - Optional callbacks for logout and token refresh failure
|
|
161
|
-
* @returns NetworkClient instance
|
|
162
|
-
*/
|
|
163
140
|
export function useFirebaseAuthNetworkClient(options) {
|
|
164
141
|
return useMemo(() => createFirebaseAuthNetworkClient(undefined, options), [options]);
|
|
165
142
|
}
|
|
143
|
+
//# sourceMappingURL=useFirebaseAuthNetworkClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFirebaseAuthNetworkClient.js","sourceRoot":"","sources":["../../src/hooks/useFirebaseAuthNetworkClient.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAOxC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAO1D,KAAK,UAAU,YAAY,CAAC,YAAY,GAAG,KAAK;IAC9C,MAAM,IAAI,GAAG,eAAe,EAAE,CAAC;IAC/B,MAAM,IAAI,GAAG,IAAI,EAAE,WAAW,CAAC;IAC/B,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IAErB,IAAI,CAAC;QACH,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IAC7C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CACX,wDAAwD,EACxD,GAAG,CACJ,CAAC;QACF,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAKD,KAAK,UAAU,UAAU,CAAC,QAAqB;IAC7C,MAAM,IAAI,GAAG,eAAe,EAAE,CAAC;IAC/B,IAAI,CAAC,IAAI;QAAE,OAAO;IAClB,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;QACpB,QAAQ,EAAE,EAAE,CAAC;IACf,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,oDAAoD,EAAE,GAAG,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC;AASD,MAAM,UAAU,+BAA+B,CAC7C,eAEC,EACD,OAA0C;IAE1C,MAAM,OAAO,GAAG,eAAe,IAAI,iBAAiB,EAAE,CAAC;IAEvD,MAAM,aA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U,EAAE,MAAM;gBAAE,WAAW,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;YAC/D,OAAO,gBAAgB,CAAI,GAAG,EAAE,WAAW,CAAC,CAAC;QAC/C,CAAC;KACF,CAAC;AACJ,CAAC;AAQD,MAAM,UAAU,4BAA4B,CAC1C,OAA0C;IAE1C,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,+BAA+B,CAAC,SAAS,EAAE,OAAO,CAAC,EACzD,CAAC,OAAO,CAAC,CACV,CAAC;AACJ,CAAC"}
|
|
@@ -1,67 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Hook to check if the current user is a site admin.
|
|
3
|
-
*
|
|
4
|
-
* Fetches user info from the backend API and caches the result using TanStack Query.
|
|
5
|
-
* This provides a single source of truth for site admin status from the backend.
|
|
6
|
-
*/
|
|
7
1
|
import type { NetworkClient, UserInfoResponse } from '@sudobility/types';
|
|
8
2
|
export type { UserInfoResponse } from '@sudobility/types';
|
|
9
|
-
/**
|
|
10
|
-
* Options for useSiteAdmin hook
|
|
11
|
-
*/
|
|
12
3
|
export interface UseSiteAdminOptions {
|
|
13
|
-
/** Network client for making API requests */
|
|
14
4
|
networkClient: NetworkClient;
|
|
15
|
-
/** Base URL of the API (e.g., "https://api.example.com/api/v1") */
|
|
16
5
|
baseUrl: string;
|
|
17
|
-
/** Firebase user ID */
|
|
18
6
|
userId: string | undefined;
|
|
19
|
-
/** Firebase ID token for authentication */
|
|
20
7
|
token: string | undefined;
|
|
21
|
-
/** Cache time in milliseconds (default: 5 minutes) */
|
|
22
8
|
staleTime?: number;
|
|
23
|
-
/** Whether to enable the query (default: true when userId and token are provided) */
|
|
24
9
|
enabled?: boolean;
|
|
25
10
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Return type for useSiteAdmin hook
|
|
28
|
-
*/
|
|
29
11
|
export interface UseSiteAdminResult {
|
|
30
|
-
/** Whether the user is a site admin */
|
|
31
12
|
isSiteAdmin: boolean;
|
|
32
|
-
/** Full user info from the API */
|
|
33
13
|
userInfo: UserInfoResponse | null;
|
|
34
|
-
/** Whether the query is loading */
|
|
35
14
|
isLoading: boolean;
|
|
36
|
-
/** Whether the query has an error */
|
|
37
15
|
isError: boolean;
|
|
38
|
-
/** Error object if query failed */
|
|
39
16
|
error: Error | null;
|
|
40
|
-
/** Refetch the user info */
|
|
41
17
|
refetch: () => void;
|
|
42
18
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Query key for site admin queries
|
|
45
|
-
*/
|
|
46
19
|
export declare const siteAdminQueryKey: (userId: string) => readonly ["siteAdmin", string];
|
|
47
|
-
/**
|
|
48
|
-
* Hook to check if the current user is a site admin.
|
|
49
|
-
*
|
|
50
|
-
* Fetches user info from the backend /users/:userId endpoint and caches the result.
|
|
51
|
-
* The backend is the single source of truth for site admin status.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```tsx
|
|
55
|
-
* const { isSiteAdmin, isLoading } = useSiteAdmin({
|
|
56
|
-
* networkClient,
|
|
57
|
-
* baseUrl: 'https://api.example.com/api/v1',
|
|
58
|
-
* userId: user?.uid,
|
|
59
|
-
* token: idToken,
|
|
60
|
-
* });
|
|
61
|
-
*
|
|
62
|
-
* if (isLoading) return <Loading />;
|
|
63
|
-
* if (isSiteAdmin) return <AdminPanel />;
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
20
|
export declare function useSiteAdmin(options: UseSiteAdminOptions): UseSiteAdminResult;
|
|
67
21
|
//# sourceMappingURL=useSiteAdmin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSiteAdmin.d.ts","sourceRoot":"","sources":["../../src/hooks/useSiteAdmin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSiteAdmin.d.ts","sourceRoot":"","sources":["../../src/hooks/useSiteAdmin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAGzE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAc1D,MAAM,WAAW,mBAAmB;IAElC,aAAa,EAAE,aAAa,CAAC;IAE7B,OAAO,EAAE,MAAM,CAAC;IAEhB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAE3B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAE1B,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAKD,MAAM,WAAW,kBAAkB;IAEjC,WAAW,EAAE,OAAO,CAAC;IAErB,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAElC,SAAS,EAAE,OAAO,CAAC;IAEnB,OAAO,EAAE,OAAO,CAAC;IAEjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAEpB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAKD,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,mCAChB,CAAC;AAqBjC,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,kBAAkB,CAqD7E"}
|
|
@@ -1,36 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Hook to check if the current user is a site admin.
|
|
3
|
-
*
|
|
4
|
-
* Fetches user info from the backend API and caches the result using TanStack Query.
|
|
5
|
-
* This provides a single source of truth for site admin status from the backend.
|
|
6
|
-
*/
|
|
7
1
|
import { useQuery } from '@tanstack/react-query';
|
|
8
|
-
/**
|
|
9
|
-
* Query key for site admin queries
|
|
10
|
-
*/
|
|
11
2
|
export const siteAdminQueryKey = (userId) => ['siteAdmin', userId];
|
|
12
|
-
/**
|
|
13
|
-
* Hook to check if the current user is a site admin.
|
|
14
|
-
*
|
|
15
|
-
* Fetches user info from the backend /users/:userId endpoint and caches the result.
|
|
16
|
-
* The backend is the single source of truth for site admin status.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```tsx
|
|
20
|
-
* const { isSiteAdmin, isLoading } = useSiteAdmin({
|
|
21
|
-
* networkClient,
|
|
22
|
-
* baseUrl: 'https://api.example.com/api/v1',
|
|
23
|
-
* userId: user?.uid,
|
|
24
|
-
* token: idToken,
|
|
25
|
-
* });
|
|
26
|
-
*
|
|
27
|
-
* if (isLoading) return <Loading />;
|
|
28
|
-
* if (isSiteAdmin) return <AdminPanel />;
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
3
|
export function useSiteAdmin(options) {
|
|
32
|
-
const { networkClient, baseUrl, userId, token, staleTime = 5 * 60 * 1000,
|
|
33
|
-
enabled, } = options;
|
|
4
|
+
const { networkClient, baseUrl, userId, token, staleTime = 5 * 60 * 1000, enabled, } = options;
|
|
34
5
|
const isEnabled = enabled ?? (!!userId && !!token);
|
|
35
6
|
const query = useQuery({
|
|
36
7
|
queryKey: siteAdminQueryKey(userId ?? ''),
|
|
@@ -46,16 +17,13 @@ export function useSiteAdmin(options) {
|
|
|
46
17
|
},
|
|
47
18
|
});
|
|
48
19
|
if (!response.ok || !response.data?.success || !response.data.data) {
|
|
49
|
-
// User not found or not authorized - not an admin
|
|
50
20
|
return null;
|
|
51
21
|
}
|
|
52
22
|
return response.data.data;
|
|
53
23
|
},
|
|
54
24
|
enabled: isEnabled,
|
|
55
25
|
staleTime,
|
|
56
|
-
// Retry once on failure (might be a transient network error)
|
|
57
26
|
retry: 1,
|
|
58
|
-
// Don't refetch on window focus for admin status
|
|
59
27
|
refetchOnWindowFocus: false,
|
|
60
28
|
});
|
|
61
29
|
return {
|
|
@@ -67,3 +35,4 @@ export function useSiteAdmin(options) {
|
|
|
67
35
|
refetch: query.refetch,
|
|
68
36
|
};
|
|
69
37
|
}
|
|
38
|
+
//# sourceMappingURL=useSiteAdmin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSiteAdmin.js","sourceRoot":"","sources":["../../src/hooks/useSiteAdmin.ts"],"names":[],"mappings":"AAO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;QACL,WAAW,EAAE,KAAK,CAAC,IAAI,EAAE,SAAS,IAAI,KAAK;QAC3C,QAAQ,EAAE,KAAK,CAAC,IAAI,IAAI,IAAI;QAC5B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,OAAO,EAAE,KAAK,CAAC,OAAO;KACvB,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview @sudobility/auth_lib - Firebase authentication utilities
|
|
3
|
-
*
|
|
4
|
-
* This library provides:
|
|
5
|
-
* - Configurable Firebase Auth initialization
|
|
6
|
-
* - Network client with automatic 401 token refresh and 403 logout handling
|
|
7
|
-
* - Firebase error message utilities
|
|
8
|
-
*/
|
|
9
1
|
export { initializeFirebaseAuth, getFirebaseApp, getFirebaseAuth, getFirebaseConfig, isFirebaseConfigured, } from './config';
|
|
10
2
|
export type { FirebaseConfig, FirebaseInitOptions, FirebaseInitResult, FirebaseAuthNetworkClientOptions, } from './config';
|
|
11
3
|
export { useFirebaseAuthNetworkClient } from './hooks';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAElB,YAAY,EACV,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,gCAAgC,GACjC,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AAEvD,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,GACtB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,0BAA0B,EAC1B,KAAK,iCAAiC,GACvC,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview @sudobility/auth_lib - Firebase authentication utilities
|
|
3
|
-
*
|
|
4
|
-
* This library provides:
|
|
5
|
-
* - Configurable Firebase Auth initialization
|
|
6
|
-
* - Network client with automatic 401 token refresh and 403 logout handling
|
|
7
|
-
* - Firebase error message utilities
|
|
8
|
-
*/
|
|
9
|
-
// Config
|
|
10
1
|
export { initializeFirebaseAuth, getFirebaseApp, getFirebaseAuth, getFirebaseConfig, isFirebaseConfigured, } from './config';
|
|
11
|
-
// Hooks
|
|
12
2
|
export { useFirebaseAuthNetworkClient } from './hooks';
|
|
13
3
|
export { useSiteAdmin, siteAdminQueryKey, } from './hooks';
|
|
14
|
-
// Utils
|
|
15
4
|
export { getFirebaseErrorMessage, getFirebaseErrorCode, formatFirebaseError, isFirebaseAuthError, } from './utils';
|
|
16
|
-
// Network
|
|
17
5
|
export { FirebaseAuthNetworkService, } from './network';
|
|
18
|
-
// Admin
|
|
19
6
|
export { parseAdminEmails, isAdminEmail, createAdminChecker } from './admin';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAUlB,OAAO,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AAEvD,OAAO,EACL,YAAY,EACZ,iBAAiB,GAIlB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,0BAA0B,GAE3B,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { initializeFirebaseAuth, getFirebaseApp, getFirebaseAuth, getFirebaseConfig, isFirebaseConfigured, } from './config/firebase-init.rn.js';
|
|
2
|
+
export type { FirebaseConfig, FirebaseInitOptions, FirebaseInitResult, FirebaseAuthNetworkClientOptions, } from './config/types.js';
|
|
3
|
+
export { useFirebaseAuthNetworkClient } from './hooks/index.js';
|
|
4
|
+
export { useSiteAdmin, siteAdminQueryKey, type UseSiteAdminOptions, type UseSiteAdminResult, type UserInfoResponse, } from './hooks/index.js';
|
|
5
|
+
export { getFirebaseErrorMessage, getFirebaseErrorCode, formatFirebaseError, isFirebaseAuthError, } from './utils/index.js';
|
|
6
|
+
export { FirebaseAuthNetworkService, type FirebaseAuthNetworkServiceOptions, } from './network/FirebaseAuthNetworkService.rn.js';
|
|
7
|
+
export { parseAdminEmails, isAdminEmail, createAdminChecker, } from './admin/index.js';
|
|
8
|
+
//# sourceMappingURL=index.rn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.rn.d.ts","sourceRoot":"","sources":["../src/index.rn.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,8BAA8B,CAAC;AAEtC,YAAY,EACV,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,gCAAgC,GACjC,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,GACtB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,0BAA0B,EAC1B,KAAK,iCAAiC,GACvC,MAAM,4CAA4C,CAAC;AAGpD,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,GACnB,MAAM,kBAAkB,CAAC"}
|
package/dist/index.rn.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { initializeFirebaseAuth, getFirebaseApp, getFirebaseAuth, getFirebaseConfig, isFirebaseConfigured, } from './config/firebase-init.rn.js';
|
|
2
|
+
export { useFirebaseAuthNetworkClient } from './hooks/index.js';
|
|
3
|
+
export { useSiteAdmin, siteAdminQueryKey, } from './hooks/index.js';
|
|
4
|
+
export { getFirebaseErrorMessage, getFirebaseErrorCode, formatFirebaseError, isFirebaseAuthError, } from './utils/index.js';
|
|
5
|
+
export { FirebaseAuthNetworkService, } from './network/FirebaseAuthNetworkService.rn.js';
|
|
6
|
+
export { parseAdminEmails, isAdminEmail, createAdminChecker, } from './admin/index.js';
|
|
7
|
+
//# sourceMappingURL=index.rn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.rn.js","sourceRoot":"","sources":["../src/index.rn.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,8BAA8B,CAAC;AAWtC,OAAO,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,EACL,YAAY,EACZ,iBAAiB,GAIlB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,0BAA0B,GAE3B,MAAM,4CAA4C,CAAC;AAGpD,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,GACnB,MAAM,kBAAkB,CAAC"}
|
|
@@ -1,27 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Firebase-aware network service with automatic token refresh and logout handling.
|
|
3
|
-
*
|
|
4
|
-
* Extends WebNetworkService to add:
|
|
5
|
-
* - On 401 (Unauthorized): Force refresh Firebase token and retry once
|
|
6
|
-
* - On 403 (Forbidden): Log the user out
|
|
7
|
-
*/
|
|
8
1
|
import { WebNetworkService } from '@sudobility/di';
|
|
9
2
|
export interface FirebaseAuthNetworkServiceOptions {
|
|
10
|
-
/** Called when user is logged out due to 403 */
|
|
11
3
|
onLogout?: () => void;
|
|
12
|
-
/** Called when token refresh fails */
|
|
13
4
|
onTokenRefreshFailed?: (error: Error) => void;
|
|
14
5
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Network service with Firebase authentication support.
|
|
17
|
-
* Automatically refreshes token on 401 and logs out on 403.
|
|
18
|
-
*/
|
|
19
6
|
export declare class FirebaseAuthNetworkService extends WebNetworkService {
|
|
20
|
-
private
|
|
7
|
+
private serviceOptions;
|
|
21
8
|
constructor(options?: FirebaseAuthNetworkServiceOptions);
|
|
22
|
-
/**
|
|
23
|
-
* Override request to add 401 retry and 403 logout handling.
|
|
24
|
-
*/
|
|
25
9
|
request(url: string, options?: RequestInit): Promise<Response>;
|
|
26
10
|
}
|
|
27
11
|
//# sourceMappingURL=FirebaseAuthNetworkService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FirebaseAuthNetworkService.d.ts","sourceRoot":"","sources":["../../src/network/FirebaseAuthNetworkService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FirebaseAuthNetworkService.d.ts","sourceRoot":"","sources":["../../src/network/FirebaseAuthNetworkService.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAInD,MAAM,WAAW,iCAAiC;IAEhD,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IAEtB,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAC/C;AAqCD,qBAAa,0BAA2B,SAAQ,iBAAiB;IAC/D,OAAO,CAAC,cAAc,CAAgD;gBAE1D,OAAO,CAAC,EAAE,iCAAiC;IAQxC,OAAO,CACpB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,QAAQ,CAAC;CAkCrB"}
|
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Firebase-aware network service with automatic token refresh and logout handling.
|
|
3
|
-
*
|
|
4
|
-
* Extends WebNetworkService to add:
|
|
5
|
-
* - On 401 (Unauthorized): Force refresh Firebase token and retry once
|
|
6
|
-
* - On 403 (Forbidden): Log the user out
|
|
7
|
-
*/
|
|
8
1
|
import { WebNetworkService } from '@sudobility/di';
|
|
9
2
|
import { signOut } from 'firebase/auth';
|
|
10
3
|
import { getFirebaseAuth } from '../config/firebase-init';
|
|
11
|
-
/**
|
|
12
|
-
* Get a fresh Firebase ID token with force refresh.
|
|
13
|
-
* Returns empty string if not authenticated.
|
|
14
|
-
*/
|
|
15
4
|
async function getAuthToken(forceRefresh = false) {
|
|
16
5
|
const auth = getFirebaseAuth();
|
|
17
6
|
const user = auth?.currentUser;
|
|
@@ -25,9 +14,6 @@ async function getAuthToken(forceRefresh = false) {
|
|
|
25
14
|
return '';
|
|
26
15
|
}
|
|
27
16
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Log the user out via Firebase.
|
|
30
|
-
*/
|
|
31
17
|
async function logoutUser(onLogout) {
|
|
32
18
|
const auth = getFirebaseAuth();
|
|
33
19
|
if (!auth)
|
|
@@ -40,27 +26,13 @@ async function logoutUser(onLogout) {
|
|
|
40
26
|
console.error('[FirebaseAuthNetworkService] Failed to sign out:', err);
|
|
41
27
|
}
|
|
42
28
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Network service with Firebase authentication support.
|
|
45
|
-
* Automatically refreshes token on 401 and logs out on 403.
|
|
46
|
-
*/
|
|
47
29
|
export class FirebaseAuthNetworkService extends WebNetworkService {
|
|
48
30
|
constructor(options) {
|
|
49
31
|
super();
|
|
50
|
-
|
|
51
|
-
enumerable: true,
|
|
52
|
-
configurable: true,
|
|
53
|
-
writable: true,
|
|
54
|
-
value: void 0
|
|
55
|
-
});
|
|
56
|
-
this.options = options;
|
|
32
|
+
this.serviceOptions = options;
|
|
57
33
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Override request to add 401 retry and 403 logout handling.
|
|
60
|
-
*/
|
|
61
34
|
async request(url, options = {}) {
|
|
62
35
|
const response = await super.request(url, options);
|
|
63
|
-
// On 401, get fresh token and retry once
|
|
64
36
|
if (response.status === 401) {
|
|
65
37
|
const freshToken = await getAuthToken(true);
|
|
66
38
|
if (freshToken) {
|
|
@@ -74,16 +46,14 @@ export class FirebaseAuthNetworkService extends WebNetworkService {
|
|
|
74
46
|
});
|
|
75
47
|
}
|
|
76
48
|
else {
|
|
77
|
-
|
|
78
|
-
this.options?.onTokenRefreshFailed?.(new Error('Failed to refresh token'));
|
|
49
|
+
this.serviceOptions?.onTokenRefreshFailed?.(new Error('Failed to refresh token'));
|
|
79
50
|
}
|
|
80
51
|
}
|
|
81
|
-
// On 403, log the user out
|
|
82
52
|
if (response.status === 403) {
|
|
83
53
|
console.warn('[FirebaseAuthNetworkService] 403 Forbidden - logging user out');
|
|
84
|
-
await logoutUser(this.
|
|
85
|
-
// Return the original response so the UI can handle it
|
|
54
|
+
await logoutUser(this.serviceOptions?.onLogout);
|
|
86
55
|
}
|
|
87
56
|
return response;
|
|
88
57
|
}
|
|
89
58
|
}
|
|
59
|
+
//# sourceMappingURL=FirebaseAuthNetworkService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FirebaseAuthNetworkService.js","sourceRoot":"","sources":["../../src/network/FirebaseAuthNetworkService.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAa1D,KAAK,UAAU,YAAY,CAAC,YAAY,GAAG,KAAK;IAC9C,MAAM,IAAI,GAAG,eAAe,EAAE,CAAC;IAC/B,MAAM,IAAI,GAAG,IAAI,EAAE,WAAW,CAAC;IAC/B,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IAErB,IAAI,CAAC;QACH,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IAC7C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,sDAAsD,EAAE,GAAG,CAAC,CAAC;QAC3E,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAKD,KAAK,UAAU,UAAU,CAAC,QAAqB;IAC7C,MAAM,IAAI,GAAG,eAAe,EAAE,CAAC;IAC/B,IAAI,CAAC,IAAI;QAAE,OAAO;IAClB,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;QACpB,QAAQ,EAAE,EAAE,CAAC;IACf,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,kDAAkD,EAAE,GAAG,CAAC,CAAC;IACzE,CAAC;AACH,CAAC;AAMD,MAAM,OAAO,0BAA2B,SAAQ,iBAAiB;IAG/D,YAAY,OAA2C;QACrD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC;IAChC,CAAC;IAKQ,KAAK,CAAC,OAAO,CACpB,GAAW,EACX,UAAuB,EAAE;QAEzB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAGnD,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;YAC5C,IAAI,UAAU,EAAE,CAAC;gBACf,MAAM,YAAY,GAAG;oBACnB,GAAI,OAAO,CAAC,OAAkC;oBAC9C,aAAa,EAAE,UAAU,UAAU,EAAE;iBACtC,CAAC;gBACF,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;oBACxB,GAAG,OAAO;oBACV,OAAO,EAAE,YAAY;iBACtB,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBAEN,IAAI,CAAC,cAAc,EAAE,oBAAoB,EAAE,CACzC,IAAI,KAAK,CAAC,yBAAyB,CAAC,CACrC,CAAC;YACJ,CAAC;QACH,CAAC;QAGD,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,OAAO,CAAC,IAAI,CACV,+DAA+D,CAChE,CAAC;YACF,MAAM,UAAU,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;QAElD,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RNNetworkService } from '@sudobility/di/rn';
|
|
2
|
+
export interface FirebaseAuthNetworkServiceOptions {
|
|
3
|
+
onLogout?: () => void;
|
|
4
|
+
onTokenRefreshFailed?: (error: Error) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare class FirebaseAuthNetworkService extends RNNetworkService {
|
|
7
|
+
private serviceOptions;
|
|
8
|
+
constructor(options?: FirebaseAuthNetworkServiceOptions);
|
|
9
|
+
request(url: string, options?: RequestInit): Promise<Response>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=FirebaseAuthNetworkService.rn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FirebaseAuthNetworkService.rn.d.ts","sourceRoot":"","sources":["../../src/network/FirebaseAuthNetworkService.rn.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAGrD,MAAM,WAAW,iCAAiC;IAEhD,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IAEtB,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAC/C;AAqCD,qBAAa,0BAA2B,SAAQ,gBAAgB;IAC9D,OAAO,CAAC,cAAc,CAAgD;gBAE1D,OAAO,CAAC,EAAE,iCAAiC;IAQxC,OAAO,CACpB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,QAAQ,CAAC;CAkCrB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { RNNetworkService } from '@sudobility/di/rn';
|
|
2
|
+
import { getFirebaseAuth } from '../config/firebase-init.rn.js';
|
|
3
|
+
async function getAuthToken(forceRefresh = false) {
|
|
4
|
+
const auth = getFirebaseAuth();
|
|
5
|
+
const user = auth?.currentUser;
|
|
6
|
+
if (!user)
|
|
7
|
+
return '';
|
|
8
|
+
try {
|
|
9
|
+
return await user.getIdToken(forceRefresh);
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
console.error('[FirebaseAuthNetworkService] Failed to get ID token:', err);
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async function logoutUser(onLogout) {
|
|
17
|
+
const auth = getFirebaseAuth();
|
|
18
|
+
if (!auth)
|
|
19
|
+
return;
|
|
20
|
+
try {
|
|
21
|
+
await auth.signOut();
|
|
22
|
+
onLogout?.();
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
console.error('[FirebaseAuthNetworkService] Failed to sign out:', err);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class FirebaseAuthNetworkService extends RNNetworkService {
|
|
29
|
+
constructor(options) {
|
|
30
|
+
super();
|
|
31
|
+
this.serviceOptions = options;
|
|
32
|
+
}
|
|
33
|
+
async request(url, options = {}) {
|
|
34
|
+
const response = await super.request(url, options);
|
|
35
|
+
if (response.status === 401) {
|
|
36
|
+
const freshToken = await getAuthToken(true);
|
|
37
|
+
if (freshToken) {
|
|
38
|
+
const retryHeaders = {
|
|
39
|
+
...options.headers,
|
|
40
|
+
Authorization: `Bearer ${freshToken}`,
|
|
41
|
+
};
|
|
42
|
+
return super.request(url, {
|
|
43
|
+
...options,
|
|
44
|
+
headers: retryHeaders,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
this.serviceOptions?.onTokenRefreshFailed?.(new Error('Failed to refresh token'));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (response.status === 403) {
|
|
52
|
+
console.warn('[FirebaseAuthNetworkService] 403 Forbidden - logging user out');
|
|
53
|
+
await logoutUser(this.serviceOptions?.onLogout);
|
|
54
|
+
}
|
|
55
|
+
return response;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=FirebaseAuthNetworkService.rn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FirebaseAuthNetworkService.rn.js","sourceRoot":"","sources":["../../src/network/FirebaseAuthNetworkService.rn.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAahE,KAAK,UAAU,YAAY,CAAC,YAAY,GAAG,KAAK;IAC9C,MAAM,IAAI,GAAG,eAAe,EAAE,CAAC;IAC/B,MAAM,IA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;oBACxB,GAAG,OAAO;oBACV,OAAO,EAAE,YAAY;iBACtB,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBAEN,IAAI,CAAC,cAAc,EAAE,oBAAoB,EAAE,CACzC,IAAI,KAAK,CAAC,yBAAyB,CAAC,CACrC,CAAC;YACJ,CAAC;QACH,CAAC;QAGD,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,OAAO,CAAC,IAAI,CACV,+DAA+D,CAChE,CAAC;YACF,MAAM,UAAU,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;QAElD,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
|
package/dist/network/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/network/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/network/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,0BAA0B,EAC1B,KAAK,iCAAiC,GACvC,MAAM,8BAA8B,CAAC"}
|
package/dist/network/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/network/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,0BAA0B,GAE3B,MAAM,8BAA8B,CAAC"}
|
|
@@ -1,32 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Firebase authentication error utilities
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Get user-friendly error message from Firebase error code
|
|
6
|
-
*
|
|
7
|
-
* @param code - Firebase error code (e.g., 'auth/user-not-found')
|
|
8
|
-
* @returns User-friendly error message
|
|
9
|
-
*/
|
|
10
1
|
export declare function getFirebaseErrorMessage(code: string): string;
|
|
11
|
-
/**
|
|
12
|
-
* Extract error code from Firebase error
|
|
13
|
-
*
|
|
14
|
-
* @param error - Error object from Firebase
|
|
15
|
-
* @returns Error code string or empty string if not found
|
|
16
|
-
*/
|
|
17
2
|
export declare function getFirebaseErrorCode(error: unknown): string;
|
|
18
|
-
/**
|
|
19
|
-
* Get user-friendly message from Firebase error object
|
|
20
|
-
*
|
|
21
|
-
* @param error - Error object from Firebase
|
|
22
|
-
* @returns User-friendly error message
|
|
23
|
-
*/
|
|
24
3
|
export declare function formatFirebaseError(error: unknown): string;
|
|
25
|
-
/**
|
|
26
|
-
* Check if an error is a Firebase auth error
|
|
27
|
-
*
|
|
28
|
-
* @param error - Error object to check
|
|
29
|
-
* @returns True if the error is a Firebase auth error
|
|
30
|
-
*/
|
|
31
4
|
export declare function isFirebaseAuthError(error: unknown): boolean;
|
|
32
5
|
//# sourceMappingURL=firebase-errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firebase-errors.d.ts","sourceRoot":"","sources":["../../src/utils/firebase-errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"firebase-errors.d.ts","sourceRoot":"","sources":["../../src/utils/firebase-errors.ts"],"names":[],"mappings":"AA2BA,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI5D;AAQD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAK3D;AAQD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAG1D;AAQD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAG3D"}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Firebase authentication error utilities
|
|
3
|
-
*/
|
|
4
|
-
/** Map of Firebase auth error codes to user-friendly messages */
|
|
5
1
|
const FIREBASE_ERROR_MESSAGES = {
|
|
6
2
|
'auth/user-not-found': 'No account found with this email',
|
|
7
3
|
'auth/wrong-password': 'Incorrect password',
|
|
@@ -16,44 +12,21 @@ const FIREBASE_ERROR_MESSAGES = {
|
|
|
16
12
|
'auth/account-exists-with-different-credential': 'An account already exists with this email using a different sign-in method.',
|
|
17
13
|
'auth/operation-not-allowed': 'This sign-in method is not enabled.',
|
|
18
14
|
};
|
|
19
|
-
/**
|
|
20
|
-
* Get user-friendly error message from Firebase error code
|
|
21
|
-
*
|
|
22
|
-
* @param code - Firebase error code (e.g., 'auth/user-not-found')
|
|
23
|
-
* @returns User-friendly error message
|
|
24
|
-
*/
|
|
25
15
|
export function getFirebaseErrorMessage(code) {
|
|
26
16
|
return (FIREBASE_ERROR_MESSAGES[code] ?? 'Something went wrong. Please try again.');
|
|
27
17
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Extract error code from Firebase error
|
|
30
|
-
*
|
|
31
|
-
* @param error - Error object from Firebase
|
|
32
|
-
* @returns Error code string or empty string if not found
|
|
33
|
-
*/
|
|
34
18
|
export function getFirebaseErrorCode(error) {
|
|
35
19
|
if (error && typeof error === 'object' && 'code' in error) {
|
|
36
20
|
return error.code;
|
|
37
21
|
}
|
|
38
22
|
return '';
|
|
39
23
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Get user-friendly message from Firebase error object
|
|
42
|
-
*
|
|
43
|
-
* @param error - Error object from Firebase
|
|
44
|
-
* @returns User-friendly error message
|
|
45
|
-
*/
|
|
46
24
|
export function formatFirebaseError(error) {
|
|
47
25
|
const code = getFirebaseErrorCode(error);
|
|
48
26
|
return getFirebaseErrorMessage(code);
|
|
49
27
|
}
|
|
50
|
-
/**
|
|
51
|
-
* Check if an error is a Firebase auth error
|
|
52
|
-
*
|
|
53
|
-
* @param error - Error object to check
|
|
54
|
-
* @returns True if the error is a Firebase auth error
|
|
55
|
-
*/
|
|
56
28
|
export function isFirebaseAuthError(error) {
|
|
57
29
|
const code = getFirebaseErrorCode(error);
|
|
58
30
|
return code.startsWith('auth/');
|
|
59
31
|
}
|
|
32
|
+
//# sourceMappingURL=firebase-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase-errors.js","sourceRoot":"","sources":["../../src/utils/firebase-errors.ts"],"names":[],"mappings":"AAKA,MAAM,uBAAuB,GAA2B;IACtD,qBAAqB,EAAE,kCAAkC;IACzD,qBAAqB,EAAE,oBAAoB;IAC3C,oBAAoB,EAAE,uBAAuB;IAC7C,yBAAyB,EAAE,2BAA2B;IACtD,2BAA2B,EAAE,2CAA2C;IACxE,oBAAoB,EAAE,wCAAwC;IAC9D,wBAAwB,EAAE,4CAA4C;IACtE,6BAA6B,EAAE,8CAA8C;IAC7E,2BAA2B,EAAE,mBAAmB;IAChD,oBAAoB,EAAE,mDAAmD;IACzE,+CAA+C,EAC7C,6EAA6E;IAC/E,4BAA4B,EAAE,qCAAqC;CACpE,CAAC;AAQF,MAAM,UAAU,uBAAuB,CAAC,IAAY;IAClD,OAAO,CACL,uBAAuB,CAAC,IAAI,CAAC,IAAI,yCAAyC,CAC3E,CAAC;AACJ,CAAC;AAQD,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;QAC1D,OAAQ,KAA0B,CAAC,IAAI,CAAC;IAC1C,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAQD,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAChD,MAAM,IAAI,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,uBAAuB,CAAC,IAAI,CAAC,CAAC;AACvC,CAAC;AAQD,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAChD,MAAM,IAAI,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sudobility/auth_lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "Firebase authentication utilities with token refresh handling",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
+
"react-native": {
|
|
12
|
+
"import": "./dist/index.rn.js",
|
|
13
|
+
"types": "./dist/index.rn.d.ts"
|
|
14
|
+
},
|
|
11
15
|
"import": "./dist/index.js",
|
|
12
16
|
"types": "./dist/index.d.ts"
|
|
13
17
|
}
|
|
@@ -29,15 +33,29 @@
|
|
|
29
33
|
"prepublishOnly": "bun run build"
|
|
30
34
|
},
|
|
31
35
|
"peerDependencies": {
|
|
32
|
-
"react": "^19.
|
|
36
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
33
37
|
"firebase": "^12.7.0",
|
|
34
|
-
"@
|
|
38
|
+
"@react-native-firebase/app": ">=18.0.0",
|
|
39
|
+
"@react-native-firebase/auth": ">=18.0.0",
|
|
40
|
+
"@sudobility/di": "^1.5.23",
|
|
35
41
|
"@sudobility/types": "^1.9.48",
|
|
36
42
|
"@tanstack/react-query": "^5.0.0"
|
|
37
43
|
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"firebase": {
|
|
46
|
+
"optional": true
|
|
47
|
+
},
|
|
48
|
+
"@react-native-firebase/app": {
|
|
49
|
+
"optional": true
|
|
50
|
+
},
|
|
51
|
+
"@react-native-firebase/auth": {
|
|
52
|
+
"optional": true
|
|
53
|
+
}
|
|
54
|
+
},
|
|
38
55
|
"devDependencies": {
|
|
39
56
|
"@sudobility/types": "^1.9.48",
|
|
40
57
|
"@tanstack/react-query": "^5.80.7",
|
|
58
|
+
"@types/node": "^22.0.0",
|
|
41
59
|
"vitest": "^4.0.4",
|
|
42
60
|
"@eslint/js": "^9.0.0",
|
|
43
61
|
"@types/bun": "^1.2.8",
|