@donotdev/auth 0.0.9 → 0.0.11
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.map +1 -1
- package/dist/AuthStore.js +1 -1
- package/dist/FirebaseAccountLinking.d.ts.map +1 -1
- package/dist/FirebaseAccountLinking.js +1 -1
- package/dist/FirebaseAuth.d.ts.map +1 -1
- package/dist/FirebaseAuth.js +1 -1
- package/dist/FirebaseSmartRecovery.js +1 -1
- package/dist/authHelpers.js +1 -1
- package/dist/components/AccountLinking.js +1 -1
- package/dist/components/AuthFallback.js +1 -1
- package/dist/components/AuthPartnerButton.js +2 -2
- package/dist/components/DeleteAccountDialogs.js +1 -1
- package/dist/components/EmailLinkForm.js +1 -1
- package/dist/components/EmailPasswordForm.js +1 -1
- package/dist/components/EmailVerification.js +1 -1
- package/dist/components/Feature.js +1 -1
- package/dist/components/FeatureGuard.js +1 -1
- package/dist/components/FeaturePlaceholder.js +1 -1
- package/dist/components/GoogleOneTap.js +1 -1
- package/dist/components/LoginModal.js +1 -1
- package/dist/components/MultipleAuthProviders.js +1 -1
- package/dist/components/NetworkStatusIndicator.js +1 -1
- package/dist/components/PasswordStrengthIndicator.js +1 -1
- package/dist/components/PasswordUpdateDialog.js +1 -1
- package/dist/components/RateLimitAlert.js +1 -1
- package/dist/components/index.js +1 -1
- package/dist/constants.js +1 -1
- package/dist/hooks/useAccountLinking.js +1 -1
- package/dist/hooks/useAuthMethodToggle.js +1 -1
- package/dist/hooks/useAuthPartner.js +1 -1
- package/dist/hooks/useDeleteAccount.js +1 -1
- package/dist/hooks/useEmailLinkAuth.js +1 -1
- package/dist/hooks/useEmailLinkForm.js +1 -1
- package/dist/hooks/useFedCM.js +1 -1
- package/dist/hooks/useGoogleOneTap.js +1 -1
- package/dist/hooks/useNetworkStatus.js +1 -1
- package/dist/index.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/useAuth.js +1 -1
- package/package.json +6 -6
- package/dist/components/__tests__/MultipleAuthProviders.test.d.ts +0 -2
- package/dist/components/__tests__/MultipleAuthProviders.test.d.ts.map +0 -1
- package/dist/components/__tests__/MultipleAuthProviders.test.js +0 -1
package/dist/useAuth.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useEffect as q,useCallback as
|
|
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("./FirebaseAuth");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.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -42,14 +42,14 @@
|
|
|
42
42
|
"type-check": "bunx tsc --noEmit"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@donotdev/components": "^0.0.
|
|
46
|
-
"@donotdev/core": "^0.0.
|
|
47
|
-
"@donotdev/firebase": "^0.0.
|
|
45
|
+
"@donotdev/components": "^0.0.21",
|
|
46
|
+
"@donotdev/core": "^0.0.27",
|
|
47
|
+
"@donotdev/firebase": "^0.0.14",
|
|
48
48
|
"firebase": "^12.9.0",
|
|
49
|
+
"lucide-react": "*",
|
|
49
50
|
"react": "^19.2.4",
|
|
50
51
|
"react-dom": "^19.2.4",
|
|
51
|
-
"react-hook-form": "*"
|
|
52
|
-
"lucide-react": "*"
|
|
52
|
+
"react-hook-form": "*"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"registry": "https://registry.npmjs.org",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MultipleAuthProviders.test.d.ts","sourceRoot":"","sources":["../../../src/components/__tests__/MultipleAuthProviders.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{jsx as s}from"react/jsx-runtime";import{describe as v,it as l,expect as a,vi as t,beforeEach as m}from"vitest";import{render as n,screen as i,fireEvent as u}from"@testing-library/react";import c from"../MultipleAuthProviders";const d=t.fn();t.mock("../../hooks/useAuth",()=>({useAuth:()=>({signInWithProvider:d})})),t.mock("@donotdev/components",()=>({Button:({children:e,onClick:o,...r})=>s("button",{onClick:o,...r,children:e}),Stack:({children:e,...o})=>s("div",{...o,children:e})})),v("MultipleAuthProviders",()=>{const e=["google","github"];m(()=>{t.clearAllMocks()}),l("renders all provided auth providers",()=>{n(s(c,{providers:e})),a(i.getByRole("button")).toBeDefined()}),l("calls signInWithProvider when provider button clicked",()=>{n(s(c,{providers:e}));const o=i.getAllByRole("button")[0];o&&(u.click(o),a(d).toHaveBeenCalled())}),l("calls onSuccess callback after successful auth",async()=>{const o=t.fn();d.mockResolvedValue({user:{id:"123"}}),n(s(c,{providers:e,onSuccess:o}));const r=i.getAllByRole("button")[0];r&&(u.click(r),await new Promise(h=>setTimeout(h,100)))}),l("shows labels when showLabels is true",()=>{n(s(c,{providers:e,showLabels:!0})),a(i.getAllByRole("button").length).toBeGreaterThan(0)})});
|