@donotdev/auth 0.0.2 → 0.0.3
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/AuthStore.d.ts +4 -9
- package/dist/AuthStore.d.ts.map +1 -1
- package/dist/AuthStore.js +1 -1
- package/dist/hooks/useGoogleOneTap.d.ts +0 -91
- package/dist/hooks/useGoogleOneTap.d.ts.map +1 -1
- package/dist/hooks/useGoogleOneTap.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/useAuth.d.ts +15 -6
- package/dist/useAuth.d.ts.map +1 -1
- package/dist/useAuth.js +1 -1
- package/package.json +5 -5
package/dist/useAuth.d.ts
CHANGED
|
@@ -4,11 +4,13 @@ import type { AuthAPI } from '@donotdev/core';
|
|
|
4
4
|
*
|
|
5
5
|
* Single entry point for all authentication operations.
|
|
6
6
|
* Lazy loads FirebaseAuth on first call and connects to store.
|
|
7
|
+
* Uses unified FeatureStatus enum for lifecycle management.
|
|
7
8
|
*
|
|
8
9
|
* **Property-based access (clean and simple):**
|
|
9
10
|
* ```typescript
|
|
10
11
|
* // ✅ State from store (reactive, re-renders on change)
|
|
11
12
|
* const user = useAuth('user');
|
|
13
|
+
* const status = useAuth('status'); // 'initializing' | 'ready' | 'degraded' | 'error'
|
|
12
14
|
* const loading = useAuth('loading');
|
|
13
15
|
* const error = useAuth('error');
|
|
14
16
|
*
|
|
@@ -18,9 +20,15 @@ import type { AuthAPI } from '@donotdev/core';
|
|
|
18
20
|
* ```
|
|
19
21
|
*
|
|
20
22
|
* **How it works:**
|
|
21
|
-
* - Store properties (user, loading, etc.) → Subscribe via Zustand (reactive)
|
|
23
|
+
* - Store properties (user, status, loading, etc.) → Subscribe via Zustand (reactive)
|
|
22
24
|
* - Methods (signInWithEmail, etc.) → Get from FirebaseAuth instance (stable)
|
|
23
25
|
*
|
|
26
|
+
* **Status-based behavior:**
|
|
27
|
+
* - `initializing`: Auth is loading (returns degraded API until ready)
|
|
28
|
+
* - `ready`: Auth fully operational (returns real API)
|
|
29
|
+
* - `degraded`: Auth unavailable (returns degraded API)
|
|
30
|
+
* - `error`: Auth encountered error (returns degraded API)
|
|
31
|
+
*
|
|
24
32
|
* **Error Handling:**
|
|
25
33
|
* All async methods throw DoNotDevError (already wrapped by FirebaseAuth/SmartRecovery).
|
|
26
34
|
*
|
|
@@ -30,20 +38,21 @@ import type { AuthAPI } from '@donotdev/core';
|
|
|
30
38
|
*
|
|
31
39
|
* @example
|
|
32
40
|
* ```typescript
|
|
41
|
+
* // Get status (re-renders when status changes)
|
|
42
|
+
* const status = useAuth('status');
|
|
43
|
+
* if (status === 'initializing') return <Loader />;
|
|
44
|
+
* if (status === 'degraded') return <Error>Auth unavailable</Error>;
|
|
45
|
+
*
|
|
33
46
|
* // Get user (re-renders when user changes)
|
|
34
47
|
* const user = useAuth('user');
|
|
35
48
|
* if (!user) return <LoginButton />;
|
|
36
49
|
*
|
|
37
|
-
* // Get error (re-renders when error changes)
|
|
38
|
-
* const error = useAuth('error');
|
|
39
|
-
* if (error) return <Alert>{error.message}</Alert>;
|
|
40
|
-
*
|
|
41
50
|
* // Get sign-in method (stable, never re-renders)
|
|
42
51
|
* const signIn = useAuth('signInWithEmail');
|
|
43
52
|
* await signIn(email, password);
|
|
44
53
|
* ```
|
|
45
54
|
*
|
|
46
|
-
* @version 0.0.
|
|
55
|
+
* @version 0.0.3
|
|
47
56
|
* @since 0.0.1
|
|
48
57
|
* @author AMBROISE PARK Consulting
|
|
49
58
|
*/
|
package/dist/useAuth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../src/useAuth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../src/useAuth.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAMV,OAAO,EAER,MAAM,gBAAgB,CAAC;AAgJxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAuTnE"}
|
package/dist/useAuth.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useEffect as
|
|
1
|
+
"use client";import{useEffect as x,useCallback as r}from"react";import{DEGRADED_AUTH_API as p,FEATURE_STATUS as c,FRAMEWORK_FEATURES as H,handleError as j,isClient as n,useFeatureConsent as q,USER_ROLES as B,SUBSCRIPTION_TIERS as K}from"@donotdev/core";import{useAuthStore as o}from"./AuthStore";import{getAuthMethod as I}from"./constants";let e=null,S=!1,y=!1;function Y(){const a=i=>{const u=o.getState();if(u.user?.role==="admin")return!0;const l=u.userProfile?.permissions;return l?l.includes(i):!1};return{navigate:i=>{const u=o.getState();return i===!1?!0:i===!0?!!u.user:!(i.required&&!u.user||i.role&&u.user?.role!==i.role||i.tier&&u.userSubscription?.tier!==i.tier||i.validate&&u.userSubscription&&u.user?.role&&!i.validate(u.user.role,u.userSubscription.tier))},view:i=>a(`${i}:view`),edit:i=>a(`${i}:edit`),delete:i=>a(`${i}:delete`),create:i=>a(`${i}:create`),has:i=>a(i),perform:(i,u)=>{const l=o.getState();if(l.user?.role==="admin")return!0;if(!a(i))return!1;if(u){const h=l.userProfile?.capabilities;if(h?.[i]){const f=h[i];for(const[E,g]of Object.entries(u))if(typeof f[E]=="number"&&typeof g=="number"&&g>f[E])return!1}}return!0}}}const Z=Y(),P=new Set(["user","loading","error","status","userProfile","userSubscription","emailVerification","partnerError","getPartnerState","setPartnerState"]);function J(a){const i=q(H.AUTH);x(()=>{if(!n())return;if(!i){o.getState().setStatus(c.DEGRADED);return}const{status:t}=o.getState();t===c.READY||S||(S=!0,(async()=>{try{const{getFirebaseAuth:s}=await import("./FirebaseAuth");e=s(),e.setStore(o.getState()),o.getState().setAuthService(e),await e.initialize(),e.onAuthStateChanged(()=>{}),y=!1}catch(s){o.getState().setStatus(c.DEGRADED),y||(j(s,{userMessage:"Authentication initialization failed",context:{operation:"useAuth.initialize"},severity:"warning",showNotification:!1}),y=!0)}finally{S=!1}})())},[i]);const u=r(async(t,s)=>!n()||!e?null:e.signInWithEmail(t,s),[]),l=r(async(t,s)=>!n()||!e?null:e.createUserWithEmail(t,s),[]),h=r(async(t,s)=>{if(!n()||!e)return null;const d=I(s);return e.signInWithPartner(t,d)},[]),f=r(async(t,s)=>{if(!n()||!e)return null;const d=I(s);return e.linkWithPartner(t,d)},[]),E=r(async t=>!n()||!e?null:e.signInWithGoogleCredential(t),[]),g=r(async()=>{if(!(!n()||!e))return e.signOut()},[]),W=r(async t=>{if(!(!n()||!e))return e.sendPasswordResetEmail(t)},[]),C=r(async t=>{if(!(!n()||!e))return e.updatePassword(t)},[]),T=r(async()=>{if(!(!n()||!e))return e.sendEmailVerification()},[]),b=r(async(t,s)=>{if(!(!n()||!e))return e.sendSignInLinkToEmail(t,s)},[]),w=r(async(t,s)=>!n()||!e?null:e.signInWithEmailLink(t,s),[]),D=r(t=>!n()||!e?!1:e.isSignInWithEmailLink(t),[]),U=r(async()=>!n()||!e?null:e.getCurrentUser(),[]),v=r(async()=>!n()||!e?{status:"pending"}:e.getEmailVerificationStatus(),[]),k=r(async()=>!n()||!e?!1:e.isEmailVerificationEnabled(),[]),F=r(async t=>!n()||!e?!1:e.hasRole(t),[]),G=r(async t=>!n()||!e?!1:e.hasTier(t),[]),L=r(async t=>!n()||!e?!1:e.hasFeature(t),[]),O=r(()=>n()?o.getState().getCustomClaims():{},[]),V=r(t=>n()?o.getState().getCustomClaim(t):null,[]),_=r(async t=>{if(!(!n()||!e))return e.reauthenticateWithPassword(t)},[]),N=r(async(t,s)=>{if(!(!n()||!e))return e.reauthenticateWithProvider(t,s)},[]),$=r(async t=>{if(!(!n()||!e))return e.deleteAccount(t)},[]),A={signInWithEmail:u,createUserWithEmail:l,signInWithPartner:h,linkWithPartner:f,signInWithGoogleCredential:E,signOut:g,sendPasswordResetEmail:W,updatePassword:C,sendEmailVerification:T,getEmailVerificationStatus:v,isEmailVerificationEnabled:k,sendSignInLinkToEmail:b,signInWithEmailLink:w,isSignInWithEmailLink:D,getCurrentUser:U,reauthenticateWithPassword:_,reauthenticateWithProvider:N,deleteAccount:$,hasRole:F,hasTier:G,hasFeature:L,getCustomClaims:O,getCustomClaim:V},R=new Set(["isAuthenticated","userRole","userTier","can"]),z=o(t=>P.has(a)?t[a]:null),M=o(t=>R.has(a)?a==="isAuthenticated"?!!t.user:a==="userRole"?t.user?.role||B.GUEST:a==="userTier"?t.userSubscription?.tier||K.FREE:a==="can"?Z:null:null),m=o(t=>t.status);return a==="status"?m:!i||m===c.INITIALIZING||m===c.DEGRADED||m===c.ERROR?p[a]:a==="isAvailable"?!0:P.has(a)?z:a in A?A[a]:R.has(a)?M:p[a]}export{J as useAuth};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@donotdev/auth",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"type-check": "tsc --noEmit"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@donotdev/components": "0.0.
|
|
46
|
-
"@donotdev/core": "0.0.
|
|
47
|
-
"@donotdev/crud": "0.0.
|
|
48
|
-
"@donotdev/firebase": "0.0.
|
|
45
|
+
"@donotdev/components": "0.0.3",
|
|
46
|
+
"@donotdev/core": "0.0.3",
|
|
47
|
+
"@donotdev/crud": "0.0.3",
|
|
48
|
+
"@donotdev/firebase": "0.0.3",
|
|
49
49
|
"firebase": "^12.5.0",
|
|
50
50
|
"react": "^19.2.3",
|
|
51
51
|
"react-dom": "^19.2.3"
|