@descope/react-sdk 2.1.1 → 2.1.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/index.d.ts CHANGED
@@ -200,6 +200,7 @@ declare const createSdkWrapper: <P extends Omit<{
200
200
  phone?: string;
201
201
  }, signUpOptions?: {
202
202
  customClaims?: Record<string, any>;
203
+ templateId?: string;
203
204
  templateOptions?: {
204
205
  [x: string]: string;
205
206
  };
@@ -215,6 +216,7 @@ declare const createSdkWrapper: <P extends Omit<{
215
216
  phone?: string;
216
217
  }, signUpOptions?: {
217
218
  customClaims?: Record<string, any>;
219
+ templateId?: string;
218
220
  templateOptions?: {
219
221
  [x: string]: string;
220
222
  };
@@ -230,6 +232,7 @@ declare const createSdkWrapper: <P extends Omit<{
230
232
  phone?: string;
231
233
  }, signUpOptions?: {
232
234
  customClaims?: Record<string, any>;
235
+ templateId?: string;
233
236
  templateOptions?: {
234
237
  [x: string]: string;
235
238
  };
@@ -245,6 +248,7 @@ declare const createSdkWrapper: <P extends Omit<{
245
248
  phone?: string;
246
249
  }, signUpOptions?: {
247
250
  customClaims?: Record<string, any>;
251
+ templateId?: string;
248
252
  templateOptions?: {
249
253
  [x: string]: string;
250
254
  };
@@ -333,6 +337,7 @@ declare const createSdkWrapper: <P extends Omit<{
333
337
  phone?: string;
334
338
  }, signUpOptions?: {
335
339
  customClaims?: Record<string, any>;
340
+ templateId?: string;
336
341
  templateOptions?: {
337
342
  [x: string]: string;
338
343
  };
@@ -348,6 +353,7 @@ declare const createSdkWrapper: <P extends Omit<{
348
353
  phone?: string;
349
354
  }, signUpOptions?: {
350
355
  customClaims?: Record<string, any>;
356
+ templateId?: string;
351
357
  templateOptions?: {
352
358
  [x: string]: string;
353
359
  };
@@ -363,6 +369,7 @@ declare const createSdkWrapper: <P extends Omit<{
363
369
  phone?: string;
364
370
  }, signUpOptions?: {
365
371
  customClaims?: Record<string, any>;
372
+ templateId?: string;
366
373
  templateOptions?: {
367
374
  [x: string]: string;
368
375
  };
@@ -378,6 +385,7 @@ declare const createSdkWrapper: <P extends Omit<{
378
385
  phone?: string;
379
386
  }, signUpOptions?: {
380
387
  customClaims?: Record<string, any>;
388
+ templateId?: string;
381
389
  templateOptions?: {
382
390
  [x: string]: string;
383
391
  };
@@ -388,6 +396,7 @@ declare const createSdkWrapper: <P extends Omit<{
388
396
  signUpOrIn: {
389
397
  sms: (loginId: string, URI?: string, signUpOptions?: {
390
398
  customClaims?: Record<string, any>;
399
+ templateId?: string;
391
400
  templateOptions?: {
392
401
  [x: string]: string;
393
402
  };
@@ -396,6 +405,7 @@ declare const createSdkWrapper: <P extends Omit<{
396
405
  }>>;
397
406
  voice: (loginId: string, URI?: string, signUpOptions?: {
398
407
  customClaims?: Record<string, any>;
408
+ templateId?: string;
399
409
  templateOptions?: {
400
410
  [x: string]: string;
401
411
  };
@@ -404,6 +414,7 @@ declare const createSdkWrapper: <P extends Omit<{
404
414
  }>>;
405
415
  whatsapp: (loginId: string, URI?: string, signUpOptions?: {
406
416
  customClaims?: Record<string, any>;
417
+ templateId?: string;
407
418
  templateOptions?: {
408
419
  [x: string]: string;
409
420
  };
@@ -412,6 +423,7 @@ declare const createSdkWrapper: <P extends Omit<{
412
423
  }>>;
413
424
  email: (loginId: string, URI?: string, signUpOptions?: {
414
425
  customClaims?: Record<string, any>;
426
+ templateId?: string;
415
427
  templateOptions?: {
416
428
  [x: string]: string;
417
429
  };
@@ -465,6 +477,7 @@ declare const createSdkWrapper: <P extends Omit<{
465
477
  signIn: (loginId: string, URI?: string, loginOptions?: _1.LoginOptions, token?: string) => Promise<_1.SdkResponse<_1.EnchantedLinkResponse>>;
466
478
  signUpOrIn: (loginId: string, URI?: string, signUpOptions?: {
467
479
  customClaims?: Record<string, any>;
480
+ templateId?: string;
468
481
  templateOptions?: {
469
482
  [x: string]: string;
470
483
  };
@@ -478,6 +491,7 @@ declare const createSdkWrapper: <P extends Omit<{
478
491
  phone?: string;
479
492
  }, signUpOptions?: {
480
493
  customClaims?: Record<string, any>;
494
+ templateId?: string;
481
495
  templateOptions?: {
482
496
  [x: string]: string;
483
497
  };
@@ -531,6 +545,7 @@ declare const createSdkWrapper: <P extends Omit<{
531
545
  notp: {
532
546
  signUpOrIn: (loginId?: string, signUpOptions?: {
533
547
  customClaims?: Record<string, any>;
548
+ templateId?: string;
534
549
  templateOptions?: {
535
550
  [x: string]: string;
536
551
  };
@@ -548,6 +563,7 @@ declare const createSdkWrapper: <P extends Omit<{
548
563
  phone?: string;
549
564
  }, signUpOptions?: {
550
565
  customClaims?: Record<string, any>;
566
+ templateId?: string;
551
567
  templateOptions?: {
552
568
  [x: string]: string;
553
569
  };
@@ -576,6 +592,7 @@ declare const createSdkWrapper: <P extends Omit<{
576
592
  phone?: string;
577
593
  }, signUpOptions?: {
578
594
  customClaims?: Record<string, any>;
595
+ templateId?: string;
579
596
  templateOptions?: {
580
597
  [x: string]: string;
581
598
  };
@@ -789,6 +806,7 @@ declare const createSdkWrapper: <P extends Omit<{
789
806
  phone?: string;
790
807
  }, signUpOptions?: {
791
808
  customClaims?: Record<string, any>;
809
+ templateId?: string;
792
810
  templateOptions?: {
793
811
  [x: string]: string;
794
812
  };
@@ -804,6 +822,7 @@ declare const createSdkWrapper: <P extends Omit<{
804
822
  phone?: string;
805
823
  }, signUpOptions?: {
806
824
  customClaims?: Record<string, any>;
825
+ templateId?: string;
807
826
  templateOptions?: {
808
827
  [x: string]: string;
809
828
  };
@@ -819,6 +838,7 @@ declare const createSdkWrapper: <P extends Omit<{
819
838
  phone?: string;
820
839
  }, signUpOptions?: {
821
840
  customClaims?: Record<string, any>;
841
+ templateId?: string;
822
842
  templateOptions?: {
823
843
  [x: string]: string;
824
844
  };
@@ -834,6 +854,7 @@ declare const createSdkWrapper: <P extends Omit<{
834
854
  phone?: string;
835
855
  }, signUpOptions?: {
836
856
  customClaims?: Record<string, any>;
857
+ templateId?: string;
837
858
  templateOptions?: {
838
859
  [x: string]: string;
839
860
  };
@@ -922,6 +943,7 @@ declare const createSdkWrapper: <P extends Omit<{
922
943
  phone?: string;
923
944
  }, signUpOptions?: {
924
945
  customClaims?: Record<string, any>;
946
+ templateId?: string;
925
947
  templateOptions?: {
926
948
  [x: string]: string;
927
949
  };
@@ -937,6 +959,7 @@ declare const createSdkWrapper: <P extends Omit<{
937
959
  phone?: string;
938
960
  }, signUpOptions?: {
939
961
  customClaims?: Record<string, any>;
962
+ templateId?: string;
940
963
  templateOptions?: {
941
964
  [x: string]: string;
942
965
  };
@@ -952,6 +975,7 @@ declare const createSdkWrapper: <P extends Omit<{
952
975
  phone?: string;
953
976
  }, signUpOptions?: {
954
977
  customClaims?: Record<string, any>;
978
+ templateId?: string;
955
979
  templateOptions?: {
956
980
  [x: string]: string;
957
981
  };
@@ -967,6 +991,7 @@ declare const createSdkWrapper: <P extends Omit<{
967
991
  phone?: string;
968
992
  }, signUpOptions?: {
969
993
  customClaims?: Record<string, any>;
994
+ templateId?: string;
970
995
  templateOptions?: {
971
996
  [x: string]: string;
972
997
  };
@@ -977,6 +1002,7 @@ declare const createSdkWrapper: <P extends Omit<{
977
1002
  signUpOrIn: {
978
1003
  sms: (loginId: string, URI?: string, signUpOptions?: {
979
1004
  customClaims?: Record<string, any>;
1005
+ templateId?: string;
980
1006
  templateOptions?: {
981
1007
  [x: string]: string;
982
1008
  };
@@ -985,6 +1011,7 @@ declare const createSdkWrapper: <P extends Omit<{
985
1011
  }>>;
986
1012
  voice: (loginId: string, URI?: string, signUpOptions?: {
987
1013
  customClaims?: Record<string, any>;
1014
+ templateId?: string;
988
1015
  templateOptions?: {
989
1016
  [x: string]: string;
990
1017
  };
@@ -993,6 +1020,7 @@ declare const createSdkWrapper: <P extends Omit<{
993
1020
  }>>;
994
1021
  whatsapp: (loginId: string, URI?: string, signUpOptions?: {
995
1022
  customClaims?: Record<string, any>;
1023
+ templateId?: string;
996
1024
  templateOptions?: {
997
1025
  [x: string]: string;
998
1026
  };
@@ -1001,6 +1029,7 @@ declare const createSdkWrapper: <P extends Omit<{
1001
1029
  }>>;
1002
1030
  email: (loginId: string, URI?: string, signUpOptions?: {
1003
1031
  customClaims?: Record<string, any>;
1032
+ templateId?: string;
1004
1033
  templateOptions?: {
1005
1034
  [x: string]: string;
1006
1035
  };
@@ -1054,6 +1083,7 @@ declare const createSdkWrapper: <P extends Omit<{
1054
1083
  signIn: (loginId: string, URI?: string, loginOptions?: _1.LoginOptions, token?: string) => Promise<_1.SdkResponse<_1.EnchantedLinkResponse>>;
1055
1084
  signUpOrIn: (loginId: string, URI?: string, signUpOptions?: {
1056
1085
  customClaims?: Record<string, any>;
1086
+ templateId?: string;
1057
1087
  templateOptions?: {
1058
1088
  [x: string]: string;
1059
1089
  };
@@ -1067,6 +1097,7 @@ declare const createSdkWrapper: <P extends Omit<{
1067
1097
  phone?: string;
1068
1098
  }, signUpOptions?: {
1069
1099
  customClaims?: Record<string, any>;
1100
+ templateId?: string;
1070
1101
  templateOptions?: {
1071
1102
  [x: string]: string;
1072
1103
  };
@@ -1120,6 +1151,7 @@ declare const createSdkWrapper: <P extends Omit<{
1120
1151
  notp: {
1121
1152
  signUpOrIn: (loginId?: string, signUpOptions?: {
1122
1153
  customClaims?: Record<string, any>;
1154
+ templateId?: string;
1123
1155
  templateOptions?: {
1124
1156
  [x: string]: string;
1125
1157
  };
@@ -1137,6 +1169,7 @@ declare const createSdkWrapper: <P extends Omit<{
1137
1169
  phone?: string;
1138
1170
  }, signUpOptions?: {
1139
1171
  customClaims?: Record<string, any>;
1172
+ templateId?: string;
1140
1173
  templateOptions?: {
1141
1174
  [x: string]: string;
1142
1175
  };
@@ -1165,6 +1198,7 @@ declare const createSdkWrapper: <P extends Omit<{
1165
1198
  phone?: string;
1166
1199
  }, signUpOptions?: {
1167
1200
  customClaims?: Record<string, any>;
1201
+ templateId?: string;
1168
1202
  templateOptions?: {
1169
1203
  [x: string]: string;
1170
1204
  };
package/dist/index.esm.js CHANGED
@@ -1,2 +1,2 @@
1
- import e,{useMemo as t,useState as r,useEffect as n,useRef as s,useCallback as o,lazy as a,useImperativeHandle as i,Suspense as l,useContext as d}from"react";import c from"@descope/web-js-sdk";const u=e.createContext(void 0),g=e=>(...t)=>{if(!e)throw Error("You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component");return e(...t)},f=e=>(...t)=>{let r;try{r=e(...t)}catch(e){console.error(e)}return r},b={"x-descope-sdk-name":"react","x-descope-sdk-version":"2.1.1"},p="undefined"!=typeof window;let m;const h=e=>{const t=c(Object.assign({persistTokens:p,autoRefresh:p},e));return m=t,t},U=()=>h({projectId:"temp pid",persistTokens:!1,autoRefresh:!1,storeLastAuthenticatedUser:!1});m=U();const w=()=>p?null==m?void 0:m.getSessionToken():(console.warn("Get session token is not supported in SSR"),""),I=()=>p?null==m?void 0:m.getRefreshToken():(console.warn("Get refresh token is not supported in SSR"),""),k=(e=w())=>null==m?void 0:m.isJwtExpired(e),E=(e=I())=>null==m?void 0:m.isJwtExpired(e),L=f(((e=w(),t)=>null==m?void 0:m.getJwtPermissions(e,t))),j=f(((e=w(),t)=>null==m?void 0:m.getJwtRoles(e,t))),v=(e=I())=>null==m?void 0:m.refresh(e);const S=({projectId:a,baseUrl:i="",baseStaticUrl:l="",sessionTokenViaCookie:d=!1,persistTokens:c=!0,storeLastAuthenticatedUser:f=!0,keepLastAuthenticatedUserAfterLogout:p=!1,children:m})=>{const[U,w]=r(),[I,k]=r(),[E,L]=r(!1),[j,v]=r(!1),S=(({projectId:e,baseUrl:r,persistTokens:n,sessionTokenViaCookie:s,storeLastAuthenticatedUser:o,keepLastAuthenticatedUserAfterLogout:a})=>t((()=>{if(e)return h({projectId:e,baseUrl:r,sessionTokenViaCookie:s,baseHeaders:b,persistTokens:n,storeLastAuthenticatedUser:o,keepLastAuthenticatedUserAfterLogout:a,autoRefresh:!0})}),[e,r,s]))({projectId:a,baseUrl:i,persistTokens:c,sessionTokenViaCookie:d,storeLastAuthenticatedUser:f,keepLastAuthenticatedUserAfterLogout:p});n((()=>{if(S){const e=S.onSessionTokenChange(k),t=S.onUserChange(w);return()=>{e(),t()}}}),[S]);const y=s(!1),R=s(!1),A=o((()=>{y.current||(y.current=!0,v(!0),g(null==S?void 0:S.refresh)().then((()=>{v(!1)})))}),[S]),C=o((()=>{R.current||(R.current=!0,L(!0),g(S.me)().then((()=>{L(!1)})))}),[S]),x=t((()=>({fetchUser:C,user:U,isUserLoading:E,isUserFetched:R.current,fetchSession:A,session:I,isSessionLoading:j,isSessionFetched:y.current,projectId:a,baseUrl:i,baseStaticUrl:l,storeLastAuthenticatedUser:f,keepLastAuthenticatedUserAfterLogout:p,setUser:w,setSession:k,sdk:S})),[C,U,E,R.current,A,I,j,y.current,a,i,l,w,k,S]);return e.createElement(u.Provider,{value:x},m)},y=a((async()=>((await import("@descope/web-component")).default.sdkConfigOverrides={baseHeaders:b,persistTokens:!1,hooks:{get beforeRequest(){return m.httpClient.hooks.beforeRequest},set beforeRequest(e){}}},{default:({projectId:t,flowId:r,baseUrl:n,baseStaticUrl:s,innerRef:o,tenant:a,theme:i,locale:l,debug:d,redirectUrl:c,client:u,form:g,styleId:f,autoFocus:b,validateOnBlur:p,storeLastAuthenticatedUser:m})=>e.createElement("descope-wc",{"project-id":t,"flow-id":r,"base-url":n,"base-static-url":s,ref:o,tenant:a,theme:i,locale:l,debug:d,client:u,form:g,"style-id":f,"redirect-url":c,"auto-focus":b,"validate-on-blur":p,"store-last-authenticated-user":m})}))),R=e.forwardRef((({flowId:s,onSuccess:a,onError:d,onReady:c,logger:g,tenant:f,theme:b,locale:p,debug:m,client:h,form:U,telemetryKey:w,redirectUrl:I,autoFocus:k,validateOnBlur:E,errorTransformer:L,styleId:j},v)=>{const[S,R]=r(null);i(v,(()=>S));const{projectId:A,baseUrl:C,baseStaticUrl:x,storeLastAuthenticatedUser:T,keepLastAuthenticatedUserAfterLogout:O,sdk:F}=e.useContext(u),J=o((async e=>{await F.httpClient.hooks.afterRequest({},new Response(JSON.stringify(e.detail))),a&&a(e)}),[a]);n((()=>{const e=S;return null==e||e.addEventListener("success",J),d&&(null==e||e.addEventListener("error",d)),c&&(null==e||e.addEventListener("ready",c)),()=>{d&&(null==e||e.removeEventListener("error",d)),c&&(null==e||e.removeEventListener("ready",c)),null==e||e.removeEventListener("success",J)}}),[S,d,J]),n((()=>{const e=S;return null==e||e.addEventListener("success",J),()=>{null==e||e.removeEventListener("success",J)}}),[S,J]),n((()=>{const e=S;return d&&(null==e||e.addEventListener("error",d)),()=>{d&&(null==e||e.removeEventListener("error",d))}}),[S,d]),n((()=>{const e=S;return c&&(null==e||e.addEventListener("ready",c)),()=>{c&&(null==e||e.removeEventListener("error",c))}}),[S,c]),n((()=>{S&&(S.errorTransformer=L)}),[S,L]),n((()=>{S&&g&&(S.logger=g)}),[S,g]);const{form:P,client:q}=t((()=>({form:JSON.stringify(U||{}),client:JSON.stringify(h||{})})),[U,h]);return e.createElement("form",null,e.createElement(l,{fallback:null},e.createElement(y,{projectId:A,flowId:s,baseUrl:C,baseStaticUrl:x,innerRef:R,tenant:f,theme:b,locale:p,debug:m,form:P,client:q,telemetryKey:w,redirectUrl:I,autoFocus:k,styleId:j,validateOnBlur:E,storeLastAuthenticatedUser:T,keepLastAuthenticatedUserAfterLogout:O})))})),A=t=>e.createElement(R,Object.assign({},t,{flowId:"sign-in"})),C=t=>e.createElement(R,Object.assign({},t,{flowId:"sign-up"})),x=t=>e.createElement(R,Object.assign({},t,{flowId:"sign-up-or-in"})),T=a((async()=>(await import("@descope/user-management-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,tenant:o,widgetId:a,theme:i,debug:l})=>e.createElement("descope-user-management-widget",{"project-id":t,"widget-id":a,"base-url":r,"base-static-url":n,theme:i,tenant:o,debug:l,ref:s})}))),O=e.forwardRef((({logger:t,tenant:s,theme:o,debug:a,widgetId:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),e.createElement(l,{fallback:null},e.createElement(T,{projectId:b,widgetId:d,baseUrl:p,baseStaticUrl:m,innerRef:f,tenant:s,theme:o,debug:a}))})),F=a((async()=>(await import("@descope/role-management-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,tenant:o,widgetId:a,theme:i,debug:l})=>e.createElement("descope-role-management-widget",{"project-id":t,"widget-id":a,"base-url":r,"base-static-url":n,theme:i,tenant:o,debug:l,ref:s})}))),J=e.forwardRef((({logger:t,tenant:s,theme:o,debug:a,widgetId:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),e.createElement(l,{fallback:null},e.createElement(F,{projectId:b,widgetId:d,baseUrl:p,baseStaticUrl:m,innerRef:f,tenant:s,theme:o,debug:a}))})),P=a((async()=>(await import("@descope/access-key-management-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,tenant:o,widgetId:a,theme:i,debug:l})=>e.createElement("descope-access-key-management-widget",{"project-id":t,"widget-id":a,"base-url":r,"base-static-url":n,theme:i,tenant:o,debug:l,ref:s})}))),q=e.forwardRef((({logger:t,tenant:s,theme:o,debug:a,widgetId:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),e.createElement(l,{fallback:null},e.createElement(P,{projectId:b,widgetId:d,baseUrl:p,baseStaticUrl:m,innerRef:f,tenant:s,theme:o,debug:a}))})),V=a((async()=>(await import("@descope/audit-management-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,tenant:o,widgetId:a,theme:i,debug:l})=>e.createElement("descope-audit-management-widget",{"project-id":t,"widget-id":a,"base-url":r,"base-static-url":n,theme:i,tenant:o,debug:l,ref:s})}))),B=e.forwardRef((({logger:t,tenant:s,theme:o,debug:a,widgetId:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),e.createElement(l,{fallback:null},e.createElement(V,{projectId:b,widgetId:d,baseUrl:p,baseStaticUrl:m,innerRef:f,tenant:s,theme:o,debug:a}))})),N=a((async()=>(await import("@descope/user-profile-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,widgetId:o,theme:a,debug:i})=>e.createElement("descope-user-profile-widget",{"project-id":t,"widget-id":o,"base-url":r,"base-static-url":n,theme:a,debug:i,ref:s})}))),Y=e.forwardRef((({logger:t,theme:s,debug:o,widgetId:a,onLogout:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),n((()=>{if(g&&d)return g.addEventListener("logout",d),()=>g.removeEventListener("logout",d)}),[g,d]),e.createElement(l,{fallback:null},e.createElement(N,{projectId:b,widgetId:a,baseUrl:p,baseStaticUrl:m,innerRef:f,theme:s,debug:o}))})),z=a((async()=>(await import("@descope/applications-portal-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,widgetId:o,theme:a,debug:i})=>e.createElement("descope-applications-portal-widget",{"project-id":t,"widget-id":o,"base-url":r,"base-static-url":n,theme:a,debug:i,ref:s})}))),G=e.forwardRef((({logger:t,theme:s,debug:o,widgetId:a},d)=>{const[c,g]=r(null);i(d,(()=>c));const{projectId:f,baseUrl:b,baseStaticUrl:p}=e.useContext(u);return n((()=>{c&&t&&(c.logger=t)}),[c,t]),e.createElement(l,{fallback:null},e.createElement(z,{projectId:f,widgetId:a,baseUrl:b,baseStaticUrl:p,innerRef:g,theme:s,debug:o}))}));var H=()=>{const e=d(u);if(!e)throw Error("You can only use this hook in the context of <AuthProvider />");return e};const K=e=>`You can only use this ${e} after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component`,M={get(e,t){if("object"==typeof e[t]&&null!==e[t])return new Proxy(e[t],M);if("function"==typeof e[t])return()=>{throw Error(K("function"))};throw Error(K("attribute"))}},$=()=>{const{sdk:e}=H();return t((()=>e||new Proxy(U(),M)),[e])},D=()=>{const{session:e,isSessionLoading:r,fetchSession:o,isSessionFetched:a}=H(),i=s(r);t((()=>{i.current=r}),[r]);const l=!e&&!r;return t((()=>{l&&!a&&(i.current=!0)}),[a]),n((()=>{l&&o()}),[o]),{isSessionLoading:i.current,sessionToken:e,isAuthenticated:!!e}},Q=()=>{const{user:e,fetchUser:o,isUserLoading:a,session:i,isUserFetched:l}=H(),[d,c]=r(!1),u=s(a),g=t((()=>!e&&!a&&i&&!d),[o,i,d]);return t((()=>{u.current=a}),[a]),t((()=>{g&&!l&&(u.current=!0)}),[g,l]),n((()=>{g&&(c(!0),o())}),[g]),{isUserLoading:u.current,user:e}};export{q as AccessKeyManagement,G as ApplicationsPortal,B as AuditManagement,S as AuthProvider,R as Descope,J as RoleManagement,A as SignInFlow,C as SignUpFlow,x as SignUpOrInFlow,O as UserManagement,Y as UserProfile,b as baseHeaders,L as getJwtPermissions,j as getJwtRoles,I as getRefreshToken,w as getSessionToken,E as isRefreshTokenExpired,k as isSessionTokenExpired,v as refresh,$ as useDescope,D as useSession,Q as useUser};
1
+ import e,{useMemo as t,useState as r,useEffect as n,useRef as s,useCallback as o,lazy as a,useImperativeHandle as i,Suspense as l,useContext as d}from"react";import c from"@descope/web-js-sdk";const u=e.createContext(void 0),g=e=>(...t)=>{if(!e)throw Error("You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component");return e(...t)},f=e=>(...t)=>{let r;try{r=e(...t)}catch(e){console.error(e)}return r},b={"x-descope-sdk-name":"react","x-descope-sdk-version":"2.1.3"},p="undefined"!=typeof window;let m;const h=e=>{const t=c(Object.assign({persistTokens:p,autoRefresh:p},e));return m=t,t},U=()=>h({projectId:"temp pid",persistTokens:!1,autoRefresh:!1,storeLastAuthenticatedUser:!1});m=U();const w=()=>p?null==m?void 0:m.getSessionToken():(console.warn("Get session token is not supported in SSR"),""),I=()=>p?null==m?void 0:m.getRefreshToken():(console.warn("Get refresh token is not supported in SSR"),""),k=(e=w())=>null==m?void 0:m.isJwtExpired(e),E=(e=I())=>null==m?void 0:m.isJwtExpired(e),L=f(((e=w(),t)=>null==m?void 0:m.getJwtPermissions(e,t))),j=f(((e=w(),t)=>null==m?void 0:m.getJwtRoles(e,t))),v=(e=I())=>null==m?void 0:m.refresh(e);const S=({projectId:a,baseUrl:i="",baseStaticUrl:l="",sessionTokenViaCookie:d=!1,persistTokens:c=!0,storeLastAuthenticatedUser:f=!0,keepLastAuthenticatedUserAfterLogout:p=!1,children:m})=>{const[U,w]=r(),[I,k]=r(),[E,L]=r(!1),[j,v]=r(!1),S=(({projectId:e,baseUrl:r,persistTokens:n,sessionTokenViaCookie:s,storeLastAuthenticatedUser:o,keepLastAuthenticatedUserAfterLogout:a})=>t((()=>{if(e)return h({projectId:e,baseUrl:r,sessionTokenViaCookie:s,baseHeaders:b,persistTokens:n,storeLastAuthenticatedUser:o,keepLastAuthenticatedUserAfterLogout:a,autoRefresh:!0})}),[e,r,s]))({projectId:a,baseUrl:i,persistTokens:c,sessionTokenViaCookie:d,storeLastAuthenticatedUser:f,keepLastAuthenticatedUserAfterLogout:p});n((()=>{if(S){const e=S.onSessionTokenChange(k),t=S.onUserChange(w);return()=>{e(),t()}}}),[S]);const y=s(!1),R=s(!1),A=o((()=>{y.current||(y.current=!0,v(!0),g(null==S?void 0:S.refresh)().then((()=>{v(!1)})))}),[S]),C=o((()=>{R.current||(R.current=!0,L(!0),g(S.me)().then((()=>{L(!1)})))}),[S]),x=t((()=>({fetchUser:C,user:U,isUserLoading:E,isUserFetched:R.current,fetchSession:A,session:I,isSessionLoading:j,isSessionFetched:y.current,projectId:a,baseUrl:i,baseStaticUrl:l,storeLastAuthenticatedUser:f,keepLastAuthenticatedUserAfterLogout:p,setUser:w,setSession:k,sdk:S})),[C,U,E,R.current,A,I,j,y.current,a,i,l,w,k,S]);return e.createElement(u.Provider,{value:x},m)},y=a((async()=>((await import("@descope/web-component")).default.sdkConfigOverrides={baseHeaders:b,persistTokens:!1,hooks:{get beforeRequest(){return m.httpClient.hooks.beforeRequest},set beforeRequest(e){}}},{default:({projectId:t,flowId:r,baseUrl:n,baseStaticUrl:s,innerRef:o,tenant:a,theme:i,locale:l,debug:d,redirectUrl:c,client:u,form:g,styleId:f,autoFocus:b,validateOnBlur:p,storeLastAuthenticatedUser:m})=>e.createElement("descope-wc",{"project-id":t,"flow-id":r,"base-url":n,"base-static-url":s,ref:o,tenant:a,theme:i,locale:l,debug:d,client:u,form:g,"style-id":f,"redirect-url":c,"auto-focus":b,"validate-on-blur":p,"store-last-authenticated-user":m})}))),R=e.forwardRef((({flowId:s,onSuccess:a,onError:d,onReady:c,logger:g,tenant:f,theme:b,locale:p,debug:m,client:h,form:U,telemetryKey:w,redirectUrl:I,autoFocus:k,validateOnBlur:E,errorTransformer:L,styleId:j},v)=>{const[S,R]=r(null);i(v,(()=>S));const{projectId:A,baseUrl:C,baseStaticUrl:x,storeLastAuthenticatedUser:T,keepLastAuthenticatedUserAfterLogout:O,sdk:F}=e.useContext(u),J=o((async e=>{await F.httpClient.hooks.afterRequest({},new Response(JSON.stringify(e.detail))),a&&a(e)}),[a]);n((()=>{const e=S;return null==e||e.addEventListener("success",J),d&&(null==e||e.addEventListener("error",d)),c&&(null==e||e.addEventListener("ready",c)),()=>{d&&(null==e||e.removeEventListener("error",d)),c&&(null==e||e.removeEventListener("ready",c)),null==e||e.removeEventListener("success",J)}}),[S,d,J]),n((()=>{const e=S;return null==e||e.addEventListener("success",J),()=>{null==e||e.removeEventListener("success",J)}}),[S,J]),n((()=>{const e=S;return d&&(null==e||e.addEventListener("error",d)),()=>{d&&(null==e||e.removeEventListener("error",d))}}),[S,d]),n((()=>{const e=S;return c&&(null==e||e.addEventListener("ready",c)),()=>{c&&(null==e||e.removeEventListener("error",c))}}),[S,c]),n((()=>{S&&(S.errorTransformer=L)}),[S,L]),n((()=>{S&&g&&(S.logger=g)}),[S,g]);const{form:P,client:q}=t((()=>({form:JSON.stringify(U||{}),client:JSON.stringify(h||{})})),[U,h]);return e.createElement("form",null,e.createElement(l,{fallback:null},e.createElement(y,{projectId:A,flowId:s,baseUrl:C,baseStaticUrl:x,innerRef:R,tenant:f,theme:b,locale:p,debug:m,form:P,client:q,telemetryKey:w,redirectUrl:I,autoFocus:k,styleId:j,validateOnBlur:E,storeLastAuthenticatedUser:T,keepLastAuthenticatedUserAfterLogout:O})))})),A=t=>e.createElement(R,Object.assign({},t,{flowId:"sign-in"})),C=t=>e.createElement(R,Object.assign({},t,{flowId:"sign-up"})),x=t=>e.createElement(R,Object.assign({},t,{flowId:"sign-up-or-in"})),T=a((async()=>(await import("@descope/user-management-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,tenant:o,widgetId:a,theme:i,debug:l})=>e.createElement("descope-user-management-widget",{"project-id":t,"widget-id":a,"base-url":r,"base-static-url":n,theme:i,tenant:o,debug:l,ref:s})}))),O=e.forwardRef((({logger:t,tenant:s,theme:o,debug:a,widgetId:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),e.createElement(l,{fallback:null},e.createElement(T,{projectId:b,widgetId:d,baseUrl:p,baseStaticUrl:m,innerRef:f,tenant:s,theme:o,debug:a}))})),F=a((async()=>(await import("@descope/role-management-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,tenant:o,widgetId:a,theme:i,debug:l})=>e.createElement("descope-role-management-widget",{"project-id":t,"widget-id":a,"base-url":r,"base-static-url":n,theme:i,tenant:o,debug:l,ref:s})}))),J=e.forwardRef((({logger:t,tenant:s,theme:o,debug:a,widgetId:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),e.createElement(l,{fallback:null},e.createElement(F,{projectId:b,widgetId:d,baseUrl:p,baseStaticUrl:m,innerRef:f,tenant:s,theme:o,debug:a}))})),P=a((async()=>(await import("@descope/access-key-management-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,tenant:o,widgetId:a,theme:i,debug:l})=>e.createElement("descope-access-key-management-widget",{"project-id":t,"widget-id":a,"base-url":r,"base-static-url":n,theme:i,tenant:o,debug:l,ref:s})}))),q=e.forwardRef((({logger:t,tenant:s,theme:o,debug:a,widgetId:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),e.createElement(l,{fallback:null},e.createElement(P,{projectId:b,widgetId:d,baseUrl:p,baseStaticUrl:m,innerRef:f,tenant:s,theme:o,debug:a}))})),V=a((async()=>(await import("@descope/audit-management-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,tenant:o,widgetId:a,theme:i,debug:l})=>e.createElement("descope-audit-management-widget",{"project-id":t,"widget-id":a,"base-url":r,"base-static-url":n,theme:i,tenant:o,debug:l,ref:s})}))),B=e.forwardRef((({logger:t,tenant:s,theme:o,debug:a,widgetId:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),e.createElement(l,{fallback:null},e.createElement(V,{projectId:b,widgetId:d,baseUrl:p,baseStaticUrl:m,innerRef:f,tenant:s,theme:o,debug:a}))})),N=a((async()=>(await import("@descope/user-profile-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,widgetId:o,theme:a,debug:i})=>e.createElement("descope-user-profile-widget",{"project-id":t,"widget-id":o,"base-url":r,"base-static-url":n,theme:a,debug:i,ref:s})}))),Y=e.forwardRef((({logger:t,theme:s,debug:o,widgetId:a,onLogout:d},c)=>{const[g,f]=r(null);i(c,(()=>g));const{projectId:b,baseUrl:p,baseStaticUrl:m}=e.useContext(u);return n((()=>{g&&t&&(g.logger=t)}),[g,t]),n((()=>{if(g&&d)return g.addEventListener("logout",d),()=>g.removeEventListener("logout",d)}),[g,d]),e.createElement(l,{fallback:null},e.createElement(N,{projectId:b,widgetId:a,baseUrl:p,baseStaticUrl:m,innerRef:f,theme:s,debug:o}))})),z=a((async()=>(await import("@descope/applications-portal-widget"),{default:({projectId:t,baseUrl:r,baseStaticUrl:n,innerRef:s,widgetId:o,theme:a,debug:i})=>e.createElement("descope-applications-portal-widget",{"project-id":t,"widget-id":o,"base-url":r,"base-static-url":n,theme:a,debug:i,ref:s})}))),G=e.forwardRef((({logger:t,theme:s,debug:o,widgetId:a},d)=>{const[c,g]=r(null);i(d,(()=>c));const{projectId:f,baseUrl:b,baseStaticUrl:p}=e.useContext(u);return n((()=>{c&&t&&(c.logger=t)}),[c,t]),e.createElement(l,{fallback:null},e.createElement(z,{projectId:f,widgetId:a,baseUrl:b,baseStaticUrl:p,innerRef:g,theme:s,debug:o}))}));var H=()=>{const e=d(u);if(!e)throw Error("You can only use this hook in the context of <AuthProvider />");return e};const K=e=>`You can only use this ${e} after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component`,M={get(e,t){if("object"==typeof e[t]&&null!==e[t])return new Proxy(e[t],M);if("function"==typeof e[t])return()=>{throw Error(K("function"))};throw Error(K("attribute"))}},$=()=>{const{sdk:e}=H();return t((()=>e||new Proxy(U(),M)),[e])},D=()=>{const{session:e,isSessionLoading:r,fetchSession:o,isSessionFetched:a}=H(),i=s(r);t((()=>{i.current=r}),[r]);const l=!e&&!r;return t((()=>{l&&!a&&(i.current=!0)}),[a]),n((()=>{l&&o()}),[o]),{isSessionLoading:i.current,sessionToken:e,isAuthenticated:!!e}},Q=()=>{const{user:e,fetchUser:o,isUserLoading:a,session:i,isUserFetched:l}=H(),[d,c]=r(!1),u=s(a),g=t((()=>!e&&!a&&i&&!d),[o,i,d]);return t((()=>{u.current=a}),[a]),t((()=>{g&&!l&&(u.current=!0)}),[g,l]),n((()=>{g&&(c(!0),o())}),[g]),{isUserLoading:u.current,user:e}};export{q as AccessKeyManagement,G as ApplicationsPortal,B as AuditManagement,S as AuthProvider,R as Descope,J as RoleManagement,A as SignInFlow,C as SignUpFlow,x as SignUpOrInFlow,O as UserManagement,Y as UserProfile,b as baseHeaders,L as getJwtPermissions,j as getJwtRoles,I as getRefreshToken,w as getSessionToken,E as isRefreshTokenExpired,k as isSessionTokenExpired,v as refresh,$ as useDescope,D as useSession,Q as useUser};
2
2
  //# sourceMappingURL=index.esm.js.map