@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/AuthStore.d.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview Auth Store
|
|
3
|
-
* @description Single source of truth
|
|
2
|
+
* @fileoverview Auth Store
|
|
3
|
+
* @description Zustand store for auth state. Single source of truth with unified FeatureStatus.
|
|
4
|
+
* Uses status enum ('initializing' | 'ready' | 'degraded' | 'error') for lifecycle management.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
* - Pure Zustand store (no events)
|
|
7
|
-
* - Direct updates from AuthService
|
|
8
|
-
* - Persists user data only
|
|
9
|
-
* - Partner state management
|
|
10
|
-
*
|
|
11
|
-
* @version 0.0.1
|
|
6
|
+
* @version 0.0.3
|
|
12
7
|
* @since 0.0.1
|
|
13
8
|
* @author AMBROISE PARK Consulting
|
|
14
9
|
*/
|
package/dist/AuthStore.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthStore.d.ts","sourceRoot":"","sources":["../src/AuthStore.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"AuthStore.d.ts","sourceRoot":"","sources":["../src/AuthStore.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,OAAO,EAKL,KAAK,SAAS,EACd,KAAK,WAAW,EAEjB,MAAM,gBAAgB,CAAC;AA0BxB,eAAO,MAAM,YAAY,iIA6LvB,CAAC"}
|
package/dist/AuthStore.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createDoNotDevStore as n}from"@donotdev/core";import{PARTNER_STATE as
|
|
1
|
+
import{createDoNotDevStore as n,FEATURE_STATUS as u}from"@donotdev/core";import{PARTNER_STATE as i}from"./constants";const o={user:null,authenticated:!1,userId:null,loading:!1,error:null,userProfile:null,userSubscription:null,partnerStates:{},partnerError:null,authService:null,emailVerification:{status:"pending"},status:u.INITIALIZING},c=n({name:"auth-store",createStore:(t,a)=>({...o,setStatus:r=>{t({status:r})},setPartnerState:(r,e,s)=>{t(l=>({partnerStates:{...l.partnerStates,[r]:e},partnerError:e==="error"&&s?{partnerId:r,error:s}:l.partnerError?.partnerId===r?null:l.partnerError}))},getPartnerState:r=>a().partnerStates[r]||i.IDLE,clearAllPartnerStates:()=>t(r=>({partnerStates:Object.keys(r.partnerStates).reduce((e,s)=>(e[s]=i.IDLE,e),{}),partnerError:null})),setAuthenticated:(r,e,s)=>{t({user:r,authenticated:!0,userId:r.id,loading:!1,error:null,status:u.READY,userSubscription:e,userProfile:s})},setUnauthenticated:()=>{t({user:null,authenticated:!1,userId:null,loading:!1,error:null,status:u.READY,userSubscription:null,userProfile:null})},setAuthLoading:r=>{t({loading:r})},setAuthError:r=>{t({error:r,loading:!1})},clearAuthError:()=>{t({error:null})},getCustomClaim:r=>a().getCustomClaimLocal(r),getCustomClaims:()=>a().getCustomClaimsLocal(),setAuthService:r=>t({authService:r}),getCustomClaimLocal:r=>{const e=a();return e.userProfile?.claims&&r in e.userProfile.claims?e.userProfile.claims[r]:e.userProfile&&r in e.userProfile?e.userProfile[r]:e.user&&r in e.user?e.user[r]:null},getCustomClaimsLocal:()=>{const r=a(),e={};return r.userProfile?.claims&&Object.assign(e,r.userProfile.claims),r.userProfile&&Object.assign(e,r.userProfile),r.user&&Object.assign(e,r.user),e},setEmailVerificationStatus:(r,e)=>t({emailVerification:{status:r,error:e}}),setUserProfile:r=>t({userProfile:r}),setUserSubscription:r=>t({userSubscription:r}),setLoading:r=>t({loading:r}),setError:r=>t({error:r}),clearError:()=>t({error:null}),reset:()=>t(o)})});export{c as useAuthStore};
|
|
@@ -1,94 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Google credential response from One Tap
|
|
3
|
-
*/
|
|
4
|
-
interface GoogleCredentialResponse {
|
|
5
|
-
/** JWT credential token */
|
|
6
|
-
credential: string;
|
|
7
|
-
/** How the user selected the credential */
|
|
8
|
-
select_by: string;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Google One Tap configuration (October 2025)
|
|
12
|
-
*/
|
|
13
|
-
interface GoogleOneTapConfig {
|
|
14
|
-
/** OAuth 2.0 client ID */
|
|
15
|
-
client_id: string;
|
|
16
|
-
/** Callback for successful authentication */
|
|
17
|
-
callback: (response: GoogleCredentialResponse) => void;
|
|
18
|
-
/** Whether to cancel on tap outside */
|
|
19
|
-
cancel_on_tap_outside?: boolean;
|
|
20
|
-
/** Whether to auto-select returning users */
|
|
21
|
-
auto_select?: boolean;
|
|
22
|
-
/** Authentication context */
|
|
23
|
-
context?: 'signin' | 'signup' | 'use';
|
|
24
|
-
/** UX mode */
|
|
25
|
-
ux_mode?: 'popup' | 'redirect';
|
|
26
|
-
/** ITP support for Safari (though Safari doesn't support FedCM yet) */
|
|
27
|
-
itp_support?: boolean;
|
|
28
|
-
/** Optional nonce for security */
|
|
29
|
-
nonce?: string;
|
|
30
|
-
/** Optional parent element ID */
|
|
31
|
-
prompt_parent_id?: string;
|
|
32
|
-
/** Optional state parameter */
|
|
33
|
-
state?: string;
|
|
34
|
-
/** MANDATORY: Always true for October 2025 */
|
|
35
|
-
use_fedcm_for_prompt: true;
|
|
36
|
-
/** Optional allowed parent origins */
|
|
37
|
-
allowed_parent_origins?: string[];
|
|
38
|
-
/** Optional CSP nonce */
|
|
39
|
-
csp_nonce?: string;
|
|
40
|
-
/**
|
|
41
|
-
* Moment callback - THE ONLY place for status handling (October 2025)
|
|
42
|
-
*
|
|
43
|
-
* @description
|
|
44
|
-
* All display, skip, and dismiss status must be handled here.
|
|
45
|
-
* The prompt() callback should only handle credentials.
|
|
46
|
-
*/
|
|
47
|
-
moment_callback: (notification: GoogleMomentNotification) => void;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Google One Tap moment notification (October 2025)
|
|
51
|
-
*
|
|
52
|
-
* @description
|
|
53
|
-
* Replaces all deprecated status methods in prompt() callback.
|
|
54
|
-
* Use these methods exclusively in moment_callback.
|
|
55
|
-
*/
|
|
56
|
-
interface GoogleMomentNotification {
|
|
57
|
-
/** Get the moment type */
|
|
58
|
-
getMomentType: () => 'display' | 'skipped' | 'dismissed';
|
|
59
|
-
/** Get skip reason (only for skipped moment) */
|
|
60
|
-
getSkippedReason?: () => string;
|
|
61
|
-
/** Get not displayed reason (only for display moment when not displayed) */
|
|
62
|
-
getNotDisplayedReason?: () => string;
|
|
63
|
-
/** Get dismissed reason (only for dismissed moment) */
|
|
64
|
-
getDismissedReason?: () => string;
|
|
65
|
-
/** Check if this is a display moment */
|
|
66
|
-
isDisplayMoment?: () => boolean;
|
|
67
|
-
/** Check if displayed (only for display moment) */
|
|
68
|
-
isDisplayed?: () => boolean;
|
|
69
|
-
/** Check if this is a skipped moment */
|
|
70
|
-
isSkippedMoment?: () => boolean;
|
|
71
|
-
/** Check if this is a dismissed moment */
|
|
72
|
-
isDismissedMoment?: () => boolean;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Global window interface extensions
|
|
76
|
-
*/
|
|
77
|
-
declare global {
|
|
78
|
-
interface Window {
|
|
79
|
-
google?: {
|
|
80
|
-
accounts?: {
|
|
81
|
-
id: {
|
|
82
|
-
initialize: (config: GoogleOneTapConfig) => void;
|
|
83
|
-
prompt: (callback?: (notification: any) => void) => void;
|
|
84
|
-
cancel?: () => void;
|
|
85
|
-
disableAutoSelect?: () => void;
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
IdentityCredential?: any;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
1
|
/**
|
|
93
2
|
* Hook options
|
|
94
3
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGoogleOneTap.d.ts","sourceRoot":"","sources":["../../src/hooks/useGoogleOneTap.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useGoogleOneTap.d.ts","sourceRoot":"","sources":["../../src/hooks/useGoogleOneTap.ts"],"names":[],"mappings":"AA+IA;;GAEG;AACH,UAAU,sBAAsB;IAC9B,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,uCAAuC;IACvC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,4CAA4C;IAC5C,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,uBAAuB;IACvB,SAAS,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAEzC,qBAAqB;IACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAEjC,sCAAsC;IACtC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhC,yBAAyB;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,uDAAuD;IACvD,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,UAAU,qBAAqB;IAC7B,0CAA0C;IAC1C,QAAQ,EAAE,OAAO,CAAC;IAElB,2CAA2C;IAC3C,SAAS,EAAE,OAAO,CAAC;IAEnB,sCAAsC;IACtC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAEpB,iCAAiC;IACjC,IAAI,EAAE,GAAG,CAAC;IAEV,kCAAkC;IAClC,MAAM,EAAE,OAAO,CAAC;IAEhB,qCAAqC;IACrC,cAAc,EAAE,OAAO,CAAC;IAExB,kDAAkD;IAClD,UAAU,EAAE,OAAO,CAAC;IAEpB,8CAA8C;IAC9C,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAErD,gCAAgC;IAChC,UAAU,EAAE,MAAM,IAAI,CAAC;IAEvB,oCAAoC;IACpC,gBAAgB,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAExD,iCAAiC;IACjC,UAAU,EAAE,OAAO,CAAC;IAEpB,6CAA6C;IAC7C,WAAW,EAAE;QACX,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,OAAO,CAAC;QACrB,cAAc,EAAE,MAAM,CAAC;KACxB,CAAC;IAEF,+DAA+D;IAC/D,WAAW,EAAE,MAAM,IAAI,CAAC;IAExB,6CAA6C;IAC7C,aAAa,EAAE,OAAO,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,UAAiB,EACjB,kBAAyB,EACzB,cAAc,EACd,QAAgB,EAChB,SAAS,EACT,OAAO,EACP,oBAAoB,EACpB,QAAQ,EACR,UAAkB,GACnB,GAAE,sBAA2B,GAAG,qBAAqB,CAiWrD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useState as L,useEffect as k,useRef as _,useCallback as B,startTransition as y,useMemo as K}from"react";import{handleError as p,getOAuthClientId as te,getEnabledAuthPartners as re,isClient as ne,useTranslation as ie,useScriptLoader as ae}from"@donotdev/core";import{useIsDark as se}from"@donotdev/components";import{useAuth as Q}from"../useAuth";import{useFedCM as ce}from"./useFedCM";function le({clientId:U,autoSelect:x=!0,cancelOnTapOutside:C=!0,promptParentId:S,disabled:d=!1,onSuccess:R,onError:s,allowedParentOrigins:A,cspNonce:I,clientOnly:F=!1}={}){const{t:r}=ie("dndev"),T=Q("user"),P=Q("signInWithGoogleCredential"),b=se(),c=U||te("google"),D=re().includes("google"),{isSupported:t,isReady:g,error:q,browserInfo:V}=ce({checkGoogleServices:!0,onError:e=>{const a=p(e,{userMessage:r("auth.fedcmNotSupported","Your browser does not support Google One Tap"),context:{operation:"fedcm_detection"},severity:"warning"});s?.(a)}}),{isLoading:X,isLoaded:M,error:z,isReady:N,load:Z,loadTriggered:$}=ae("https://accounts.google.com/gsi/client",{enabled:D&&!!c&&!d&&g&&t,nonce:I,checkExisting:!0,isLoaded:()=>!!window.google?.accounts?.id,onError:e=>{const a=p(e,{userMessage:r("auth.googleScriptLoadError","Failed to load Google Identity Services"),context:{operation:"google_script_load"},severity:"error"});s?.(a)}}),[O,J]=L(!1),[Y,H]=L(null),ee=_(null),i=_(!1),l=_(null),E=_(0),[W,m]=L(!1),w="gsi_hide_until",de=600*1e3,v=K(()=>D&&!!c&&!d&&!T&&t&&(F?O:!0)&&!W,[D,c,d,T,t,F,O,W]),oe=K(()=>!t&&g?new Error(r("auth.fedcmRequired","Google One Tap requires a modern browser (Chrome 116+ or Edge 116+)")):z||q||Y,[z,q,Y,t,g,r]),f=B(async e=>{try{if(!e||typeof e!="string")throw new Error("Invalid credential format");await P(e),y(()=>{R?.(e)})}catch(a){const n=p(a,{userMessage:r("auth.googleOneTapError","Google One Tap authentication failed"),context:{operation:"google_one_tap_signin",credentialLength:e?.length||0},severity:"error"});throw y(()=>{H(n)}),s?.(n),n}},[P,R,s,r]),G=B(()=>{if(!ne()||!N||!c||!window.google?.accounts?.id||!t||i.current)return;const e=Date.now(),a=e-E.current,n=600*1e3;if(!(a<n&&E.current>0))try{i.current=!0,E.current=e;const h={client_id:c,callback:async o=>{try{await f(o.credential)}catch(j){p(j,{userMessage:"Google One Tap credential handling failed",context:{operation:"google_one_tap_callback"},severity:"error"})}},auto_select:x,cancel_on_tap_outside:C,context:"signin",ux_mode:"popup",itp_support:!0,state:b?"dark":"light",use_fedcm_for_prompt:!0,allowed_parent_origins:A,csp_nonce:I,moment_callback:o=>{const j=o.getMomentType();if(o.isDisplayMoment?.()){if(!o.isDisplayed?.()&&o.getNotDisplayedReason){i.current=!1;try{const u=Date.now()+n;localStorage.setItem(w,String(u)),m(!0)}catch{}}}else if(o.isSkippedMoment?.()){i.current=!1;try{const u=Date.now()+n;localStorage.setItem(w,String(u)),m(!0)}catch{}}else if(o.isDismissedMoment?.()){i.current=!1;try{const u=Date.now()+n;localStorage.setItem(w,String(u)),m(!0)}catch{}}}};S&&(h.prompt_parent_id=S),window.google.accounts.id.initialize(h),l.current&&window.clearTimeout(l.current),l.current=window.setTimeout(()=>{window.google?.accounts?.id
|
|
1
|
+
"use client";import{useState as L,useEffect as k,useRef as _,useCallback as B,startTransition as y,useMemo as K}from"react";import{handleError as p,getOAuthClientId as te,getEnabledAuthPartners as re,isClient as ne,useTranslation as ie,useScriptLoader as ae}from"@donotdev/core";import{useIsDark as se}from"@donotdev/components";import{useAuth as Q}from"../useAuth";import{useFedCM as ce}from"./useFedCM";function le({clientId:U,autoSelect:x=!0,cancelOnTapOutside:C=!0,promptParentId:S,disabled:d=!1,onSuccess:R,onError:s,allowedParentOrigins:A,cspNonce:I,clientOnly:F=!1}={}){const{t:r}=ie("dndev"),T=Q("user"),P=Q("signInWithGoogleCredential"),b=se(),c=U||te("google"),D=re().includes("google"),{isSupported:t,isReady:g,error:q,browserInfo:V}=ce({checkGoogleServices:!0,onError:e=>{const a=p(e,{userMessage:r("auth.fedcmNotSupported","Your browser does not support Google One Tap"),context:{operation:"fedcm_detection"},severity:"warning"});s?.(a)}}),{isLoading:X,isLoaded:M,error:z,isReady:N,load:Z,loadTriggered:$}=ae("https://accounts.google.com/gsi/client",{enabled:D&&!!c&&!d&&g&&t,nonce:I,checkExisting:!0,isLoaded:()=>!!window.google?.accounts?.id,onError:e=>{const a=p(e,{userMessage:r("auth.googleScriptLoadError","Failed to load Google Identity Services"),context:{operation:"google_script_load"},severity:"error"});s?.(a)}}),[O,J]=L(!1),[Y,H]=L(null),ee=_(null),i=_(!1),l=_(null),E=_(0),[W,m]=L(!1),w="gsi_hide_until",de=600*1e3,v=K(()=>D&&!!c&&!d&&!T&&t&&(F?O:!0)&&!W,[D,c,d,T,t,F,O,W]),oe=K(()=>!t&&g?new Error(r("auth.fedcmRequired","Google One Tap requires a modern browser (Chrome 116+ or Edge 116+)")):z||q||Y,[z,q,Y,t,g,r]),f=B(async e=>{try{if(!e||typeof e!="string")throw new Error("Invalid credential format");await P(e),y(()=>{R?.(e)})}catch(a){const n=p(a,{userMessage:r("auth.googleOneTapError","Google One Tap authentication failed"),context:{operation:"google_one_tap_signin",credentialLength:e?.length||0},severity:"error"});throw y(()=>{H(n)}),s?.(n),n}},[P,R,s,r]),G=B(()=>{if(!ne()||!N||!c||!window.google?.accounts?.id||!t||i.current)return;const e=Date.now(),a=e-E.current,n=600*1e3;if(!(a<n&&E.current>0))try{i.current=!0,E.current=e;const h={client_id:c,callback:async o=>{try{await f(o.credential)}catch(j){p(j,{userMessage:"Google One Tap credential handling failed",context:{operation:"google_one_tap_callback"},severity:"error"})}},auto_select:x,cancel_on_tap_outside:C,context:"signin",ux_mode:"popup",itp_support:!0,state:b?"dark":"light",use_fedcm_for_prompt:!0,allowed_parent_origins:A,csp_nonce:I,moment_callback:o=>{const j=o.getMomentType();if(o.isDisplayMoment?.()){if(!o.isDisplayed?.()&&o.getNotDisplayedReason){i.current=!1;try{const u=Date.now()+n;localStorage.setItem(w,String(u)),m(!0)}catch{}}}else if(o.isSkippedMoment?.()){i.current=!1;try{const u=Date.now()+n;localStorage.setItem(w,String(u)),m(!0)}catch{}}else if(o.isDismissedMoment?.()){i.current=!1;try{const u=Date.now()+n;localStorage.setItem(w,String(u)),m(!0)}catch{}}}};S&&(h.prompt_parent_id=S),window.google.accounts.id.initialize(h),l.current&&window.clearTimeout(l.current),l.current=window.setTimeout(()=>{window.google?.accounts?.id?.prompt(o=>{o?.credential&&f(o.credential)}),l.current=null},100)}catch(h){const o=p(h,{userMessage:r("auth.googleOneTapInitError","Failed to initialize Google One Tap"),context:{operation:"google_one_tap_initialize",fedcmSupported:t},severity:"error"});y(()=>{H(o)}),s?.(o),i.current=!1}},[N,c,t,x,C,S,b,f,s,A,I,r]);return k(()=>{if(typeof window<"u"){y(()=>{J(!0)});try{const e=Number(localStorage.getItem(w)||0);m(e>Date.now())}catch{}}},[]),k(()=>{M&&!d&&v&&g&&G()},[M,d,v,g,G]),k(()=>()=>{l.current&&window.clearTimeout(l.current),i.current=!1},[]),{isLoaded:M,isLoading:X,error:oe,user:T,isDark:b,fedcmSupported:t,isHydrated:O,containerRef:ee,initialize:G,handleCredential:f,shouldShow:v,browserInfo:V,triggerLoad:Z,loadTriggered:$}}export{le as useGoogleOneTap};
|