@service_laboratory/auth 2.0.7 → 2.0.8
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 +3 -3
- package/dist/index.js +4 -4
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare interface AccountUser {
|
|
|
16
16
|
email: string | null;
|
|
17
17
|
roles: Role[];
|
|
18
18
|
is_enabled: boolean;
|
|
19
|
-
|
|
19
|
+
is_email_verified: boolean;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
declare interface ActivateRequest {
|
|
@@ -35,9 +35,9 @@ export declare class Auth {
|
|
|
35
35
|
logout(): void;
|
|
36
36
|
startResetPassword(values: StartResetPasswordRequest): Promise<AxiosResponse<any, any>>;
|
|
37
37
|
resetPassword(values: ResetPasswordRequest): Promise<void>;
|
|
38
|
-
_initUserData({ user,
|
|
38
|
+
_initUserData({ user, token }: {
|
|
39
39
|
user: AccountUser;
|
|
40
|
-
|
|
40
|
+
token: string;
|
|
41
41
|
}): void;
|
|
42
42
|
_setAuthData(token: string): void;
|
|
43
43
|
_clearAuthData(): void;
|
package/dist/index.js
CHANGED
|
@@ -4819,7 +4819,7 @@ const Ie = "Authorization", ar = () => ({
|
|
|
4819
4819
|
email: null,
|
|
4820
4820
|
roles: [],
|
|
4821
4821
|
is_enabled: !1,
|
|
4822
|
-
|
|
4822
|
+
is_email_verified: !1
|
|
4823
4823
|
},
|
|
4824
4824
|
isAuthenticated: !1,
|
|
4825
4825
|
isLoaded: !1
|
|
@@ -4853,8 +4853,8 @@ class un {
|
|
|
4853
4853
|
}
|
|
4854
4854
|
}
|
|
4855
4855
|
async login(r) {
|
|
4856
|
-
const t = await this.httpClient.post("/api/auth/account/login", r), { user: o,
|
|
4857
|
-
return
|
|
4856
|
+
const t = await this.httpClient.post("/api/auth/account/login", r), { user: o, token: n } = t.data;
|
|
4857
|
+
return this._initUserData({ user: o, token: n }), o;
|
|
4858
4858
|
}
|
|
4859
4859
|
register(r) {
|
|
4860
4860
|
return this.httpClient.post("/api/auth/account/register", r);
|
|
@@ -4873,7 +4873,7 @@ class un {
|
|
|
4873
4873
|
const t = await this.httpClient.post("/api/auth/account/reset-password", r);
|
|
4874
4874
|
this._initUserData(t.data);
|
|
4875
4875
|
}
|
|
4876
|
-
_initUserData({ user: r,
|
|
4876
|
+
_initUserData({ user: r, token: t }) {
|
|
4877
4877
|
this._setAuthData(t), ie.setState(() => ({
|
|
4878
4878
|
user: r,
|
|
4879
4879
|
isAuthenticated: !0,
|
package/dist/index.umd.cjs
CHANGED
|
@@ -106,4 +106,4 @@ See https://react.dev/link/invalid-hook-call for tips about how to debug and fix
|
|
|
106
106
|
*
|
|
107
107
|
* This source code is licensed under the ISC license.
|
|
108
108
|
* See the LICENSE file in the root directory of this source tree.
|
|
109
|
-
*/const Xo=rr("eye",[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);function Jo(e){const[r,t]=O.useState(!1);return T.jsx("div",{className:"flex flex-col gap-6",children:T.jsxs(_o,{children:[T.jsxs(wo,{children:[T.jsx(ko,{className:"text-2xl",children:e.loginFormTitle}),T.jsx(Oo,{children:e.loginFormDescription})]}),T.jsx(So,{children:T.jsx(Go,{...e.form,children:T.jsx("form",{onSubmit:e.form.handleSubmit(e.submit),children:T.jsxs("div",{className:"flex flex-col gap-6",children:[T.jsxs("div",{className:"grid gap-2",children:[T.jsx(Wt,{htmlFor:"email",children:e.emailLabel}),T.jsx(qt,{control:e.form.control,name:"email",render:({field:o})=>T.jsx(Jt,{children:T.jsx(Zt,{children:T.jsx(Qt,{id:"email",type:"email",placeholder:"m@example.com",required:!0,...o})})})})]}),T.jsxs("div",{className:"grid gap-2",children:[T.jsxs("div",{className:"flex items-center",children:[T.jsx(Wt,{htmlFor:"password",children:e.passwordLabel}),e.resetPasswordLinkComponent?e.resetPasswordLinkComponent():null]}),T.jsx(qt,{control:e.form.control,name:"password",render:({field:o})=>T.jsx(Jt,{children:T.jsx(Zt,{className:"relative",children:T.jsxs("div",{className:"relative",children:[r?T.jsx(qo,{className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 z-10 cursor-pointer",onClick:()=>{t(!1)}}):T.jsx(Xo,{className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 z-10 cursor-pointer",onClick:()=>{t(!0)}}),T.jsx(Qt,{type:r?"text":"password",placeholder:"********",...o,className:"pr-10"})]})})})})]}),T.jsx(xo,{type:"submit",className:"w-full",children:e.submitButtonLabel})]})})})})]})})}const me=new WeakMap,je=new WeakMap,Te={current:[]};let Ke=!1;const Ae=new Set,or=new Map;function nr(e){const r=Array.from(e).sort((t,o)=>t instanceof le&&t.options.deps.includes(o)?1:o instanceof le&&o.options.deps.includes(t)?-1:0);for(const t of r){if(Te.current.includes(t))continue;Te.current.push(t),t.recompute();const o=je.get(t);if(o)for(const n of o){const s=me.get(n);s&&nr(s)}}}function Zo(e){e.listeners.forEach(r=>r({prevVal:e.prevState,currentVal:e.state}))}function Qo(e){e.listeners.forEach(r=>r({prevVal:e.prevState,currentVal:e.state}))}function en(e){if(Ae.add(e),!Ke)try{for(Ke=!0;Ae.size>0;){const r=Array.from(Ae);Ae.clear();for(const t of r){const o=or.get(t)??t.prevState;t.prevState=o,Zo(t)}for(const t of r){const o=me.get(t);o&&(Te.current.push(t),nr(o))}for(const t of r){const o=me.get(t);if(o)for(const n of o)Qo(n)}}}finally{Ke=!1,Te.current=[],or.clear()}}function tn(e){return typeof e=="function"}class qe{constructor(r,t){this.listeners=new Set,this.subscribe=o=>{var n,s;this.listeners.add(o);const d=(s=(n=this.options)==null?void 0:n.onSubscribe)==null?void 0:s.call(n,o,this);return()=>{this.listeners.delete(o),d?.()}},this.prevState=r,this.state=r,this.options=t}setState(r){var t,o,n;this.prevState=this.state,(t=this.options)!=null&&t.updateFn?this.state=this.options.updateFn(this.prevState)(r):tn(r)?this.state=r(this.prevState):this.state=r,(n=(o=this.options)==null?void 0:o.onUpdate)==null||n.call(o),en(this)}}class le{constructor(r){this.listeners=new Set,this._subscriptions=[],this.lastSeenDepValues=[],this.getDepVals=()=>{const t=[],o=[];for(const n of this.options.deps)t.push(n.prevState),o.push(n.state);return this.lastSeenDepValues=o,{prevDepVals:t,currDepVals:o,prevVal:this.prevState??void 0}},this.recompute=()=>{var t,o;this.prevState=this.state;const{prevDepVals:n,currDepVals:s,prevVal:d}=this.getDepVals();this.state=this.options.fn({prevDepVals:n,currDepVals:s,prevVal:d}),(o=(t=this.options).onUpdate)==null||o.call(t)},this.checkIfRecalculationNeededDeeply=()=>{for(const s of this.options.deps)s instanceof le&&s.checkIfRecalculationNeededDeeply();let t=!1;const o=this.lastSeenDepValues,{currDepVals:n}=this.getDepVals();for(let s=0;s<n.length;s++)if(n[s]!==o[s]){t=!0;break}t&&this.recompute()},this.mount=()=>(this.registerOnGraph(),this.checkIfRecalculationNeededDeeply(),()=>{this.unregisterFromGraph();for(const t of this._subscriptions)t()}),this.subscribe=t=>{var o,n;this.listeners.add(t);const s=(n=(o=this.options).onSubscribe)==null?void 0:n.call(o,t,this);return()=>{this.listeners.delete(t),s?.()}},this.options=r,this.state=r.fn({prevDepVals:void 0,prevVal:void 0,currDepVals:this.getDepVals().currDepVals})}registerOnGraph(r=this.options.deps){for(const t of r)if(t instanceof le)t.registerOnGraph(),this.registerOnGraph(t.options.deps);else if(t instanceof qe){let o=me.get(t);o||(o=new Set,me.set(t,o)),o.add(this);let n=je.get(this);n||(n=new Set,je.set(this,n)),n.add(t)}}unregisterFromGraph(r=this.options.deps){for(const t of r)if(t instanceof le)this.unregisterFromGraph(t.options.deps);else if(t instanceof qe){const o=me.get(t);o&&o.delete(this);const n=je.get(this);n&&n.delete(t)}}}const Xe="Authorization",sr=()=>({user:{id:null,email:null,roles:[],is_enabled:!1,
|
|
109
|
+
*/const Xo=rr("eye",[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);function Jo(e){const[r,t]=O.useState(!1);return T.jsx("div",{className:"flex flex-col gap-6",children:T.jsxs(_o,{children:[T.jsxs(wo,{children:[T.jsx(ko,{className:"text-2xl",children:e.loginFormTitle}),T.jsx(Oo,{children:e.loginFormDescription})]}),T.jsx(So,{children:T.jsx(Go,{...e.form,children:T.jsx("form",{onSubmit:e.form.handleSubmit(e.submit),children:T.jsxs("div",{className:"flex flex-col gap-6",children:[T.jsxs("div",{className:"grid gap-2",children:[T.jsx(Wt,{htmlFor:"email",children:e.emailLabel}),T.jsx(qt,{control:e.form.control,name:"email",render:({field:o})=>T.jsx(Jt,{children:T.jsx(Zt,{children:T.jsx(Qt,{id:"email",type:"email",placeholder:"m@example.com",required:!0,...o})})})})]}),T.jsxs("div",{className:"grid gap-2",children:[T.jsxs("div",{className:"flex items-center",children:[T.jsx(Wt,{htmlFor:"password",children:e.passwordLabel}),e.resetPasswordLinkComponent?e.resetPasswordLinkComponent():null]}),T.jsx(qt,{control:e.form.control,name:"password",render:({field:o})=>T.jsx(Jt,{children:T.jsx(Zt,{className:"relative",children:T.jsxs("div",{className:"relative",children:[r?T.jsx(qo,{className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 z-10 cursor-pointer",onClick:()=>{t(!1)}}):T.jsx(Xo,{className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 z-10 cursor-pointer",onClick:()=>{t(!0)}}),T.jsx(Qt,{type:r?"text":"password",placeholder:"********",...o,className:"pr-10"})]})})})})]}),T.jsx(xo,{type:"submit",className:"w-full",children:e.submitButtonLabel})]})})})})]})})}const me=new WeakMap,je=new WeakMap,Te={current:[]};let Ke=!1;const Ae=new Set,or=new Map;function nr(e){const r=Array.from(e).sort((t,o)=>t instanceof le&&t.options.deps.includes(o)?1:o instanceof le&&o.options.deps.includes(t)?-1:0);for(const t of r){if(Te.current.includes(t))continue;Te.current.push(t),t.recompute();const o=je.get(t);if(o)for(const n of o){const s=me.get(n);s&&nr(s)}}}function Zo(e){e.listeners.forEach(r=>r({prevVal:e.prevState,currentVal:e.state}))}function Qo(e){e.listeners.forEach(r=>r({prevVal:e.prevState,currentVal:e.state}))}function en(e){if(Ae.add(e),!Ke)try{for(Ke=!0;Ae.size>0;){const r=Array.from(Ae);Ae.clear();for(const t of r){const o=or.get(t)??t.prevState;t.prevState=o,Zo(t)}for(const t of r){const o=me.get(t);o&&(Te.current.push(t),nr(o))}for(const t of r){const o=me.get(t);if(o)for(const n of o)Qo(n)}}}finally{Ke=!1,Te.current=[],or.clear()}}function tn(e){return typeof e=="function"}class qe{constructor(r,t){this.listeners=new Set,this.subscribe=o=>{var n,s;this.listeners.add(o);const d=(s=(n=this.options)==null?void 0:n.onSubscribe)==null?void 0:s.call(n,o,this);return()=>{this.listeners.delete(o),d?.()}},this.prevState=r,this.state=r,this.options=t}setState(r){var t,o,n;this.prevState=this.state,(t=this.options)!=null&&t.updateFn?this.state=this.options.updateFn(this.prevState)(r):tn(r)?this.state=r(this.prevState):this.state=r,(n=(o=this.options)==null?void 0:o.onUpdate)==null||n.call(o),en(this)}}class le{constructor(r){this.listeners=new Set,this._subscriptions=[],this.lastSeenDepValues=[],this.getDepVals=()=>{const t=[],o=[];for(const n of this.options.deps)t.push(n.prevState),o.push(n.state);return this.lastSeenDepValues=o,{prevDepVals:t,currDepVals:o,prevVal:this.prevState??void 0}},this.recompute=()=>{var t,o;this.prevState=this.state;const{prevDepVals:n,currDepVals:s,prevVal:d}=this.getDepVals();this.state=this.options.fn({prevDepVals:n,currDepVals:s,prevVal:d}),(o=(t=this.options).onUpdate)==null||o.call(t)},this.checkIfRecalculationNeededDeeply=()=>{for(const s of this.options.deps)s instanceof le&&s.checkIfRecalculationNeededDeeply();let t=!1;const o=this.lastSeenDepValues,{currDepVals:n}=this.getDepVals();for(let s=0;s<n.length;s++)if(n[s]!==o[s]){t=!0;break}t&&this.recompute()},this.mount=()=>(this.registerOnGraph(),this.checkIfRecalculationNeededDeeply(),()=>{this.unregisterFromGraph();for(const t of this._subscriptions)t()}),this.subscribe=t=>{var o,n;this.listeners.add(t);const s=(n=(o=this.options).onSubscribe)==null?void 0:n.call(o,t,this);return()=>{this.listeners.delete(t),s?.()}},this.options=r,this.state=r.fn({prevDepVals:void 0,prevVal:void 0,currDepVals:this.getDepVals().currDepVals})}registerOnGraph(r=this.options.deps){for(const t of r)if(t instanceof le)t.registerOnGraph(),this.registerOnGraph(t.options.deps);else if(t instanceof qe){let o=me.get(t);o||(o=new Set,me.set(t,o)),o.add(this);let n=je.get(this);n||(n=new Set,je.set(this,n)),n.add(t)}}unregisterFromGraph(r=this.options.deps){for(const t of r)if(t instanceof le)this.unregisterFromGraph(t.options.deps);else if(t instanceof qe){const o=me.get(t);o&&o.delete(this);const n=je.get(this);n&&n.delete(t)}}}const Xe="Authorization",sr=()=>({user:{id:null,email:null,roles:[],is_enabled:!1,is_email_verified:!1},isAuthenticated:!1,isLoaded:!1}),ce=new qe(sr()),rn=new le({fn:()=>!!ce.state.user?.roles.find(e=>e.name==="admin"),deps:[ce]});class on{accountStore;httpClient;constructor(r){this.httpClient=r,this.accountStore=ce}initAuthData(){const r=localStorage.getItem("token");r&&(this.httpClient.defaults.headers.common[Xe]=r)}async load(){try{const{data:r}=await this.httpClient.get("/api/auth/account/me");ce.setState(()=>({user:r,isAuthenticated:!0,isLoaded:!0}))}catch{ce.setState(r=>({...r,isLoaded:!0}))}}async login(r){const t=await this.httpClient.post("/api/auth/account/login",r),{user:o,token:n}=t.data;return this._initUserData({user:o,token:n}),o}register(r){return this.httpClient.post("/api/auth/account/register",r)}async activate(r){const t=await this.httpClient.post("/api/auth/account/activate",r);this._initUserData(t.data)}logout(){ce.setState(()=>({...sr(),isLoaded:!0})),this._clearAuthData()}startResetPassword(r){return this.httpClient.post("/api/auth/account/start-reset-password",r)}async resetPassword(r){const t=await this.httpClient.post("/api/auth/account/reset-password",r);this._initUserData(t.data)}_initUserData({user:r,token:t}){this._setAuthData(t),ce.setState(()=>({user:r,isAuthenticated:!0,isLoaded:!0}))}_setAuthData(r){localStorage.setItem("token",r),this.httpClient.defaults.headers.common[Xe]=r}_clearAuthData(){localStorage.removeItem("token"),delete this.httpClient.defaults.headers.common[Xe]}}te.Auth=on,te.LoginForm=Jo,te.isAdmin=rn,Object.defineProperty(te,Symbol.toStringTag,{value:"Module"})}));
|