@donotdev/auth 0.0.14 → 0.0.15

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 (47) hide show
  1. package/dist/AuthStore.js +1 -1
  2. package/dist/authHelpers.js +1 -1
  3. package/dist/components/AccountLinking.js +1 -1
  4. package/dist/components/AuthFallback.js +1 -1
  5. package/dist/components/AuthPartnerButton.js +2 -2
  6. package/dist/components/DeleteAccountDialogs.js +1 -1
  7. package/dist/components/EmailLinkForm.js +1 -1
  8. package/dist/components/EmailPasswordForm.js +1 -1
  9. package/dist/components/EmailVerification.js +1 -1
  10. package/dist/components/Feature.js +1 -1
  11. package/dist/components/FeatureGuard.js +1 -1
  12. package/dist/components/FeaturePlaceholder.js +1 -1
  13. package/dist/components/GoogleOneTap.js +1 -1
  14. package/dist/components/LoginModal.js +1 -1
  15. package/dist/components/MultipleAuthProviders.js +1 -1
  16. package/dist/components/NetworkStatusIndicator.js +1 -1
  17. package/dist/components/PasswordStrengthIndicator.js +1 -1
  18. package/dist/components/PasswordUpdateDialog.js +1 -1
  19. package/dist/components/RateLimitAlert.js +1 -1
  20. package/dist/components/index.js +1 -1
  21. package/dist/constants.d.ts +3 -47
  22. package/dist/constants.d.ts.map +1 -1
  23. package/dist/constants.js +1 -1
  24. package/dist/hooks/useAccountLinking.js +1 -1
  25. package/dist/hooks/useAuthMethodToggle.js +1 -1
  26. package/dist/hooks/useAuthPartner.js +1 -1
  27. package/dist/hooks/useDeleteAccount.js +1 -1
  28. package/dist/hooks/useEmailLinkAuth.js +1 -1
  29. package/dist/hooks/useEmailLinkForm.js +1 -1
  30. package/dist/hooks/useFedCM.js +1 -1
  31. package/dist/hooks/useGoogleOneTap.js +1 -1
  32. package/dist/hooks/useNetworkStatus.js +1 -1
  33. package/dist/index.d.ts +1 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +1 -1
  36. package/dist/tsconfig.tsbuildinfo +1 -1
  37. package/dist/useAuth.js +1 -1
  38. package/package.json +2 -2
  39. package/dist/FirebaseAccountLinking.d.ts +0 -29
  40. package/dist/FirebaseAccountLinking.d.ts.map +0 -1
  41. package/dist/FirebaseAccountLinking.js +0 -1
  42. package/dist/FirebaseAuth.d.ts +0 -607
  43. package/dist/FirebaseAuth.d.ts.map +0 -1
  44. package/dist/FirebaseAuth.js +0 -1
  45. package/dist/FirebaseSmartRecovery.d.ts +0 -52
  46. package/dist/FirebaseSmartRecovery.d.ts.map +0 -1
  47. package/dist/FirebaseSmartRecovery.js +0 -1
package/dist/useAuth.js CHANGED
@@ -1 +1 @@
1
- "use client";import{useEffect as q,useCallback as n,useRef as B}from"react";import{DEGRADED_AUTH_API as P,FEATURE_STATUS as c,FRAMEWORK_FEATURES as K,handleError as Y,hasProvider as Z,getProvider as J,isClient as i,useFeatureConsent as Q,USER_ROLES as A,SUBSCRIPTION_TIERS as X,hasRoleAccess as y,hasTierAccess as ee}from"@donotdev/core";import{useAuthStore as o}from"./AuthStore";import{getAuthMethod as W}from"./constants";let e=null;const oe=()=>e;let d=!1,R=!1;function te(){const s=r=>{const a=o.getState();if(y(a.user?.role,A.ADMIN))return!0;const l=a.userProfile?.permissions;return l?l.includes(r):!1};return{navigate:r=>{const a=o.getState();return r===!1?!0:r===!0?!!a.user:!(r.required&&!a.user||r.role&&!y(a.user?.role,r.role)||r.tier&&!ee(a.userSubscription?.tier,r.tier)||r.validate&&a.userSubscription&&a.user?.role&&!r.validate(a.user.role,a.userSubscription.tier))},view:r=>s(`${r}:view`),edit:r=>s(`${r}:edit`),delete:r=>s(`${r}:delete`),create:r=>s(`${r}:create`),has:r=>s(r),perform:(r,a)=>{const l=o.getState();if(y(l.user?.role,A.ADMIN))return!0;if(!s(r))return!1;if(a){const h=l.userProfile?.capabilities;if(h?.[r]){const f=h[r];for(const[g,E]of Object.entries(a))if(typeof f[g]=="number"&&typeof E=="number"&&E>f[g])return!1}}return!0}}}const re=te(),C=new Set(["user","loading","error","status","userProfile","userSubscription","emailVerification","partnerError","getPartnerState","setPartnerState"]);function ie(s){const r=Q(K.AUTH),a=B(null);q(()=>{if(!i())return;if(!r){o.getState().setStatus(c.DEGRADED);return}const{status:t}=o.getState();return t===c.READY||d?void 0:(d=!0,(async()=>{try{if(Z("auth"))e=J("auth");else{const{getFirebaseAuth:u}=await import("./FirebaseAuth");e=u()}if(!e)return;"setStore"in e&&e.setStore(o.getState()),o.getState().setAuthService(e),await e.initialize(),a.current=e.onAuthStateChanged(()=>{}),R=!1}catch(u){o.getState().setStatus(c.DEGRADED),R||(Y(u,{userMessage:"Authentication initialization failed",context:{operation:"useAuth.initialize"},severity:"warning",showNotification:!1}),R=!0)}finally{d=!1}})(),()=>{a.current?.(),a.current=null,d=!1})},[r]);const l=n(async(t,u)=>!i()||!e?null:e.signInWithEmail(t,u),[]),h=n(async(t,u)=>!i()||!e?null:e.createUserWithEmail(t,u),[]),f=n(async(t,u)=>{if(!i()||!e)return null;const m=W(u);return e.signInWithPartner(t,m)},[]),g=n(async(t,u)=>{if(!i()||!e)return null;const m=W(u);return e.linkWithPartner(t,m)},[]),E=n(async t=>!i()||!e?null:e.signInWithGoogleCredential(t),[]),T=n(async()=>{if(!(!i()||!e))return e.signOut()},[]),D=n(async t=>{if(!(!i()||!e))return e.sendPasswordResetEmail(t)},[]),b=n(async t=>{if(!(!i()||!e))return e.updatePassword(t)},[]),w=n(async()=>{if(!(!i()||!e))return e.sendEmailVerification()},[]),v=n(async(t,u)=>{if(!(!i()||!e))return e.sendSignInLinkToEmail(t,u)},[]),U=n(async(t,u)=>!i()||!e?null:e.signInWithEmailLink(t,u),[]),k=n(t=>!i()||!e?!1:e.isSignInWithEmailLink(t),[]),F=n(async()=>!i()||!e?null:e.getCurrentUser(),[]),G=n(async()=>!i()||!e?{status:"pending"}:e.getEmailVerificationStatus(),[]),L=n(async()=>!i()||!e?!1:e.isEmailVerificationEnabled(),[]),O=n(async t=>!i()||!e?!1:e.hasRole(t),[]),V=n(async t=>!i()||!e?!1:e.hasTier(t),[]),N=n(async t=>!i()||!e?!1:e.hasFeature(t),[]),_=n(()=>i()?o.getState().getCustomClaims():{},[]),M=n(t=>i()?o.getState().getCustomClaim(t):null,[]),$=n(async t=>{if(!(!i()||!e))return e.reauthenticateWithPassword(t)},[]),z=n(async(t,u)=>{if(!(!i()||!e))return e.reauthenticateWithProvider(t,u)},[]),x=n(async t=>{if(!(!i()||!e))return e.deleteAccount(t)},[]),I={signInWithEmail:l,createUserWithEmail:h,signInWithPartner:f,linkWithPartner:g,signInWithGoogleCredential:E,signOut:T,sendPasswordResetEmail:D,updatePassword:b,sendEmailVerification:w,getEmailVerificationStatus:G,isEmailVerificationEnabled:L,sendSignInLinkToEmail:v,signInWithEmailLink:U,isSignInWithEmailLink:k,getCurrentUser:F,reauthenticateWithPassword:$,reauthenticateWithProvider:z,deleteAccount:x,hasRole:O,hasTier:V,hasFeature:N,getCustomClaims:_,getCustomClaim:M},p=new Set(["isAuthenticated","userRole","userTier","can"]),H=o(t=>C.has(s)?t[s]:null),j=o(t=>p.has(s)?s==="isAuthenticated"?!!t.user:s==="userRole"?t.user?.role||A.GUEST:s==="userTier"?t.userSubscription?.tier||X.FREE:s==="can"?re:null:null),S=o(t=>t.status);return s==="status"?S:!r||S===c.INITIALIZING||S===c.DEGRADED||S===c.ERROR?P[s]:s==="isAvailable"?!0:C.has(s)?H:s in I?I[s]:p.has(s)?j:P[s]}export{ie as useAuth};
1
+ "use client";import{useEffect as q,useCallback as i,useRef as x}from"react";import{DEGRADED_AUTH_API as W,FEATURE_STATUS as f,FRAMEWORK_FEATURES as B,handleError as Z,hasProvider as J,getProvider as Q,isClient as n,useFeatureConsent as X,USER_ROLES as A,SUBSCRIPTION_TIERS as k,hasRoleAccess as I,hasTierAccess as tt}from"@donotdev/core";import{useAuthStore as o}from"./AuthStore";import{getAuthMethod as b}from"./constants";let t=null;const at=()=>t;let g=!1,R=!1;function et(){const s=r=>{const u=o.getState();if(I(u.user?.role,A.ADMIN))return!0;const l=u.userProfile?.permissions;return l?l.includes(r):!1};return{navigate:r=>{const u=o.getState();return r===!1?!0:r===!0?!!u.user:!(r.required&&!u.user||r.role&&!I(u.user?.role,r.role)||r.tier&&!tt(u.userSubscription?.tier,r.tier)||r.validate&&u.userSubscription&&u.user?.role&&!r.validate(u.user.role,u.userSubscription.tier))},view:r=>s(`${r}:view`),edit:r=>s(`${r}:edit`),delete:r=>s(`${r}:delete`),create:r=>s(`${r}:create`),has:r=>s(r),perform:(r,u)=>{const l=o.getState();if(I(l.user?.role,A.ADMIN))return!0;if(!s(r))return!1;if(u){const h=l.userProfile?.capabilities;if(h?.[r]){const d=h[r];for(const[E,m]of Object.entries(u))if(typeof d[E]=="number"&&typeof m=="number"&&m>d[E])return!1}}return!0}}}const rt=et(),T=new Set(["user","loading","error","status","userProfile","userSubscription","emailVerification","partnerError","getPartnerState","setPartnerState"]);function ot(s){const r=X(B.AUTH),u=x(null);q(()=>{if(!n())return;if(!r){o.getState().setStatus(f.DEGRADED);return}const{status:e}=o.getState();return e===f.READY||g?void 0:(g=!0,(async()=>{try{if(J("auth"))t=Q("auth");else{const{getFirebaseAuth:c}=await import("@donotdev/firebase");t=c()}if(!t)return;"setStore"in t&&t.setStore(o.getState()),o.getState().setAuthService(t),await t.initialize(),u.current=t.onAuthStateChanged(()=>{}),R=!1}catch(c){o.getState().setStatus(f.DEGRADED),R||(Z(c,{userMessage:"Authentication initialization failed",context:{operation:"useAuth.initialize"},severity:"warning",showNotification:!1}),R=!0)}finally{g=!1}})(),()=>{u.current?.(),u.current=null,g=!1})},[r]);const l=i(async(e,a)=>!n()||!t?null:t.signInWithEmail(e,a),[]),h=i(async(e,a)=>!n()||!t?null:t.createUserWithEmail(e,a),[]),d=i(async(e,a)=>{if(!n()||!t)return null;const c=b(a);return t.signInWithPartner(e,c)},[]),E=i(async(e,a)=>{if(!n()||!t)return null;const c=b(a);return t.linkWithPartner(e,c)},[]),m=i(async e=>!n()||!t?null:t.signInWithGoogleCredential(e),[]),D=i(async()=>{if(!(!n()||!t))return t.signOut()},[]),w=i(async e=>{if(!(!n()||!t))return t.sendPasswordResetEmail(e)},[]),y=i(async e=>{if(!(!n()||!t))return t.updatePassword(e)},[]),v=i(async()=>{if(!(!n()||!t))return t.sendEmailVerification()},[]),U=i(async(e,a)=>{if(!(!n()||!t))return t.sendSignInLinkToEmail(e,a)},[]),C=i(async(e,a)=>!n()||!t?null:t.signInWithEmailLink(e,a),[]),F=i(e=>!n()||!t?!1:t.isSignInWithEmailLink(e),[]),V=i(async()=>!n()||!t?null:t.getCurrentUser(),[]),G=i(async()=>!n()||!t?{status:"pending"}:t.getEmailVerificationStatus(),[]),L=i(async()=>!n()||!t?!1:t.isEmailVerificationEnabled(),[]),O=i(async e=>!n()||!t?!1:t.hasRole(e),[]),M=i(async e=>!n()||!t?!1:t.hasTier(e),[]),N=i(async e=>!n()||!t?!1:t.hasFeature(e),[]),_=i(()=>n()?o.getState().getCustomClaims():{},[]),z=i(e=>n()?o.getState().getCustomClaim(e):null,[]),$=i(async e=>{if(!(!n()||!t))return t.reauthenticateWithPassword(e)},[]),K=i(async(e,a)=>{if(!(!n()||!t))return t.reauthenticateWithProvider(e,a)},[]),H=i(async e=>{if(!(!n()||!t))return t.deleteAccount(e)},[]),p={signInWithEmail:l,createUserWithEmail:h,signInWithPartner:d,linkWithPartner:E,signInWithGoogleCredential:m,signOut:D,sendPasswordResetEmail:w,updatePassword:y,sendEmailVerification:v,getEmailVerificationStatus:G,isEmailVerificationEnabled:L,sendSignInLinkToEmail:U,signInWithEmailLink:C,isSignInWithEmailLink:F,getCurrentUser:V,reauthenticateWithPassword:$,reauthenticateWithProvider:K,deleteAccount:H,hasRole:O,hasTier:M,hasFeature:N,getCustomClaims:_,getCustomClaim:z},P=new Set(["isAuthenticated","userRole","userTier","can"]),Y=o(e=>T.has(s)?e[s]:null),j=o(e=>P.has(s)?s==="isAuthenticated"?!!e.user:s==="userRole"?e.user?.role||A.GUEST:s==="userTier"?e.userSubscription?.tier||k.FREE:s==="can"?rt:null:null),S=o(e=>e.status);return s==="status"?S:!r||S===f.INITIALIZING||S===f.DEGRADED||S===f.ERROR?W[s]:s==="isAvailable"?!0:T.has(s)?Y:s in p?p[s]:P.has(s)?j:W[s]}export{ot as useAuth};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@donotdev/auth",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -44,7 +44,7 @@
44
44
  "peerDependencies": {
45
45
  "@donotdev/components": "^0.0.24",
46
46
  "@donotdev/core": "^0.0.30",
47
- "@donotdev/firebase": "^0.0.16",
47
+ "@donotdev/firebase": "^0.0.17",
48
48
  "firebase": "^12.9.0",
49
49
  "lucide-react": "*",
50
50
  "react": "^19.2.4",
@@ -1,29 +0,0 @@
1
- import { type AuthResult, type AuthPartnerId } from '@donotdev/core';
2
- import { getFirebaseSDK, type FirebaseUser } from '@donotdev/firebase';
3
- import { type AuthMethod } from './constants';
4
- type FirebaseSDKInstance = ReturnType<typeof getFirebaseSDK>;
5
- export interface AccountLinkingDependencies {
6
- sdk: FirebaseSDKInstance;
7
- createProviderFromConfig: (partnerId: AuthPartnerId) => any;
8
- createAuthResult: (user: FirebaseUser, isNewUser?: boolean) => AuthResult;
9
- getExistingProvider: (sdk: FirebaseSDKInstance, error: any, email: string) => Promise<AuthPartnerId | null>;
10
- }
11
- /**
12
- * Account Linking: Intelligent routing
13
- * Shows progress toasts and handles linking internally
14
- *
15
- * @version 0.0.1
16
- * @since 0.0.1
17
- * @author AMBROISE PARK Consulting
18
- */
19
- export declare function handleOAuthLinking(error: any, attemptedProvider: AuthPartnerId, method: AuthMethod, deps: AccountLinkingDependencies): Promise<AuthResult | null>;
20
- /**
21
- * Clear account linking state from sessionStorage
22
- *
23
- * @version 0.0.1
24
- * @since 0.0.1
25
- * @author AMBROISE PARK Consulting
26
- */
27
- export declare function clearAccountLinkingState(): void;
28
- export {};
29
- //# sourceMappingURL=FirebaseAccountLinking.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FirebaseAccountLinking.d.ts","sourceRoot":"","sources":["../src/FirebaseAccountLinking.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,aAAa,EAInB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,cAAc,EAEd,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAE7D,KAAK,mBAAmB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAE7D,MAAM,WAAW,0BAA0B;IACzC,GAAG,EAAE,mBAAmB,CAAC;IACzB,wBAAwB,EAAE,CAAC,SAAS,EAAE,aAAa,KAAK,GAAG,CAAC;IAC5D,gBAAgB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,SAAS,CAAC,EAAE,OAAO,KAAK,UAAU,CAAC;IAC1E,mBAAmB,EAAE,CACnB,GAAG,EAAE,mBAAmB,EACxB,KAAK,EAAE,GAAG,EACV,KAAK,EAAE,MAAM,KACV,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC;CACpC;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,GAAG,EACV,iBAAiB,EAAE,aAAa,EAChC,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,0BAA0B,GAC/B,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAiG5B;AAgMD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAG/C"}
@@ -1 +0,0 @@
1
- import{toast as r}from"@donotdev/components";import{safeSessionStorage as a,isDev as l}from"@donotdev/core";import{OAuthProvider as m}from"@donotdev/firebase";import{getAuthMethod as d}from"./constants";async function g(i,n,s,o){const t=i.customData?.email||i.email;if(!t)throw l(),r("error","Could not determine account email"),i;const u=m.credentialFromError(i);if(u)try{const c=u.toJSON();a.setItem("originalCredential",JSON.stringify(c))}catch{l()}else l();const e=await o.getExistingProvider(o.sdk,i,t);if(!e)throw r("error","Could not determine existing account type"),i;return e==="password"?await p(t,n,o):e==="emailLink"?await f(t,n,o):n==="password"&&e!=="password"?await k(t,e,s,o):n==="emailLink"&&e!=="emailLink"?await h(t,e,s,o):await w(t,e,s,n,o)}async function p(i,n,s){const o={email:i,existingProvider:"password",newProvider:n,timestamp:Date.now()};return a.setItem("accountLinkingInfo",JSON.stringify(o)),r("info",`Please sign in with your password to link your ${n} account`),null}async function f(i,n,s){const o={email:i,existingProvider:"emailLink",newProvider:n,timestamp:Date.now()};return a.setItem("accountLinkingInfo",JSON.stringify(o)),r("info",`Please check your email for a sign-in link to link your ${n} account`),null}async function w(i,n,s,o,t){r("info",`Account linking required. Signing you in with ${n} to link your ${o} account...`);const u={email:i,existingProvider:n,newProvider:o,timestamp:Date.now()};a.setItem("accountLinkingInfo",JSON.stringify(u));const e=t.createProviderFromConfig(n);if(d(s)==="popup"){r("info",`You have an existing ${n} account. Opening popup to link accounts...`);try{const c=await t.sdk.signInWithPopup(e);return t.createAuthResult(c.user,!1)}catch(c){throw l(),c.code==="auth/popup-blocked"||c.code==="auth/popup-closed-by-user"?(r("error","Popup was blocked. Please allow popups for this site and try again, or use a different browser."),a.removeItem("accountLinkingInfo"),a.removeItem("originalCredential"),new Error("Popup blocked. Please allow popups to complete account linking in development mode.")):c}}else return r("info",`You have an existing ${n} account. Redirecting to link accounts...`),await t.sdk.signInWithRedirect(e),null}async function k(i,n,s,o){r("info","We can't automatically link password/email accounts. First sign in using your original method, then go to Profile \u2192 Link accounts to connect this provider.");const t={email:i,existingProvider:"password",newProvider:n,timestamp:Date.now()};return a.setItem("accountLinkingInfo",JSON.stringify(t)),null}async function h(i,n,s,o){r("info","We can't automatically link password/email accounts. First sign in using your original method, then go to Profile \u2192 Link accounts to connect this provider.");const t={email:i,existingProvider:"emailLink",newProvider:n,timestamp:Date.now()};return a.setItem("accountLinkingInfo",JSON.stringify(t)),null}function y(){a.removeItem("accountLinkingInfo"),a.removeItem("originalCredential")}export{y as clearAccountLinkingState,g as handleOAuthLinking};