@ciscode/ui-authentication-kit 1.0.4 → 1.0.6
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/components/RequirePermissions.js +1 -1
- package/dist/components/RequirePermissions.js.map +1 -1
- package/dist/index.mjs +492 -448
- package/dist/index.umd.js +7 -37
- package/dist/pages/auth/ForgotPasswordPage.d.ts +3 -0
- package/dist/pages/auth/ForgotPasswordPage.d.ts.map +1 -0
- package/dist/pages/auth/ForgotPasswordPage.js +70 -0
- package/dist/pages/auth/ForgotPasswordPage.js.map +1 -0
- package/dist/pages/auth/ResetPasswordPage.d.ts +3 -0
- package/dist/pages/auth/ResetPasswordPage.d.ts.map +1 -0
- package/dist/pages/auth/ResetPasswordPage.js +93 -0
- package/dist/pages/auth/ResetPasswordPage.js.map +1 -0
- package/dist/pages/auth/SignInPage.d.ts.map +1 -1
- package/dist/pages/auth/SignInPage.js +3 -2
- package/dist/pages/auth/SignInPage.js.map +1 -1
- package/dist/pages/auth/SignUpPage.d.ts.map +1 -1
- package/dist/pages/auth/SignUpPage.js +19 -8
- package/dist/pages/auth/SignUpPage.js.map +1 -1
- package/dist/providers/AuthProvider.d.ts.map +1 -1
- package/dist/providers/AuthProvider.js +6 -2
- package/dist/providers/AuthProvider.js.map +1 -1
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,49 +1,19 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(f,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react"),require("axios"),require("jwt-decode"),require("react-dom"),require("@ciscode/ui-translate-core"),require("lucide-react"),require("react-router-dom")):typeof define=="function"&&define.amd?define(["exports","react","axios","jwt-decode","react-dom","@ciscode/ui-translate-core","lucide-react","react-router-dom"],e):(f=typeof globalThis<"u"?globalThis:f||self,e(f["ciscode-model"]={},f.React,f.axios,f.jwt_decode,f.ReactDOM,f.CISCODETranslateCore,f.LucideReact,f.ReactRouterDOM))})(this,function(f,e,ee,fe,he,F,oe,h){"use strict";function pe(t){const l=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const s=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(l,r,s.get?s:{enumerable:!0,get:()=>t[r]})}}return l.default=t,Object.freeze(l)}const A=pe(e),ie=e.createContext(null);function X(){const t=e.useContext(ie);if(!t)throw new Error("useAuthConfig must be used within an AuthConfigProvider");return t}const ce=e.createContext(null);function L(){const t=e.useContext(ce);if(!t)throw new Error("useAuthState must be inside <AuthProvider>");return t}function te(t){const l=fe.jwtDecode(t);return{id:l.sub,email:l.email??"",roles:l.roles??[],permissions:l.permissions??[],modules:l.modules??[],tenantId:l.tenantId??""}}let le=!1;function xe(){le=!1}function be(t,l){t.defaults.withCredentials=!0;const r=`${l.baseUrl}${l.refreshEndpoint??"/auth/refresh-token"}`;t.interceptors.request.use(a=>{const o=l.getAccessToken();return o&&(a.headers.Authorization=`Bearer ${o}`),a});let s=!1,n=[];return t.interceptors.response.use(a=>a,async a=>{var m;const o=a.config;if(((m=a.response)==null?void 0:m.status)!==401||!o||o._retry)return Promise.reject(a);if(o._retry=!0,!s){s=!0;try{const{data:i}=await ee.post(r,{},{withCredentials:!0});return l.setAccessToken(i.accessToken),n.forEach(d=>d(i.accessToken)),n=[],t.request(o)}catch(i){return!!l.getAccessToken()&&!le&&(le=!0,l.logout()),n.forEach(w=>w(null)),n=[],Promise.reject(i)}finally{s=!1}}return new Promise((i,d)=>{n.push(w=>{if(!w)return d(a);(o.headers??(o.headers={})).Authorization=`Bearer ${w}`,i(t.request(o))})})}),t}const we=({onConfirm:t})=>{const l=F.useT("authLib");return e.useEffect(()=>{const{body:r}=document,s=r.style.overflow,n=r.style.pointerEvents;return r.style.overflow="hidden",r.style.pointerEvents="none",()=>{r.style.overflow=s,r.style.pointerEvents=n}},[]),he.createPortal(e.createElement("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/40 backdrop-blur-sm"},e.createElement("div",{className:"pointer-events-auto w-full max-w-sm rounded-xl bg-white p-6 shadow-xl"},e.createElement("h2",{className:"mb-4 text-xl font-semibold text-gray-800 ltr:text-left rtl:text-center"},l("sessionExpired.title")),e.createElement("p",{className:"mb-8 text-sm text-gray-600 ltr:text-left rtl:text-center"},l("sessionExpired.message")),e.createElement("div",{className:"flex justify-end"},e.createElement("button",{onClick:t,className:`
|
|
2
2
|
rounded-lg bg-red-600 px-4 py-2 text-sm font-medium text-white
|
|
3
3
|
hover:bg-red-700 focus-visible:outline focus-visible:outline-2
|
|
4
4
|
focus-visible:outline-offset-2 focus-visible:outline-red-600
|
|
5
|
-
`},l("sessionExpired.button"))))),document.body)},
|
|
5
|
+
`},l("sessionExpired.button"))))),document.body)},P=({label:t,type:l="text",placeholder:r,color:s="",value:n,onChange:a})=>{const o=A.useId();return A.createElement("div",{className:"mt-8 flex flex-col"},t&&A.createElement("label",{htmlFor:o,className:"self-start text-base text-black dark:text-white block ltr:text-left rtl:text-right"},t),A.createElement("input",{id:o,type:l,placeholder:r||void 0,value:n,onChange:m=>a==null?void 0:a(m.target.value),className:`
|
|
6
6
|
px-4 py-4 mt-3.5 text-sm font-light rounded-lg border border-solid w-full
|
|
7
7
|
ltr:text-left rtl:text-right
|
|
8
|
-
${
|
|
9
|
-
`}))},
|
|
10
|
-
* @license lucide-react v0.481.0 - ISC
|
|
11
|
-
*
|
|
12
|
-
* This source code is licensed under the ISC license.
|
|
13
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
14
|
-
*/const xe=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),oe=(...t)=>t.filter((l,n,r)=>!!l&&l.trim()!==""&&r.indexOf(l)===n).join(" ").trim();/**
|
|
15
|
-
* @license lucide-react v0.481.0 - ISC
|
|
16
|
-
*
|
|
17
|
-
* This source code is licensed under the ISC license.
|
|
18
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
19
|
-
*/var pe={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
|
|
20
|
-
* @license lucide-react v0.481.0 - ISC
|
|
21
|
-
*
|
|
22
|
-
* This source code is licensed under the ISC license.
|
|
23
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
24
|
-
*/const be=e.forwardRef(({color:t="currentColor",size:l=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:o="",children:s,iconNode:a,...c},i)=>e.createElement("svg",{ref:i,...pe,width:l,height:l,stroke:t,strokeWidth:r?Number(n)*24/Number(l):n,className:oe("lucide",o),...c},[...a.map(([u,b])=>e.createElement(u,b)),...Array.isArray(s)?s:[s]]));/**
|
|
25
|
-
* @license lucide-react v0.481.0 - ISC
|
|
26
|
-
*
|
|
27
|
-
* This source code is licensed under the ISC license.
|
|
28
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
29
|
-
*/const ae=(t,l)=>{const n=e.forwardRef(({className:r,...o},s)=>e.createElement(be,{ref:s,iconNode:l,className:oe(`lucide-${xe(t)}`,r),...o}));return n.displayName=`${t}`,n};/**
|
|
30
|
-
* @license lucide-react v0.481.0 - ISC
|
|
31
|
-
*
|
|
32
|
-
* This source code is licensed under the ISC license.
|
|
33
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
34
|
-
*/const we=ae("TriangleAlert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/**
|
|
35
|
-
* @license lucide-react v0.481.0 - ISC
|
|
36
|
-
*
|
|
37
|
-
* This source code is licensed under the ISC license.
|
|
38
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
39
|
-
*/const ye=ae("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),ie=({message:t,dismissAfterMs:l=4e3})=>{const n=O.useT("authLib"),[r,o]=e.useState(!1);return e.useEffect(()=>{if(o(!!t),t&&l>0){const s=window.setTimeout(()=>o(!1),l);return()=>window.clearTimeout(s)}},[t,l]),!r||!t?null:e.createElement("div",{role:"alert","aria-live":"assertive",className:`
|
|
8
|
+
${s}
|
|
9
|
+
`}))},me=({icon:t,label:l})=>A.createElement("div",{className:"flex gap-5 px-8 py-3 items-center bg-indigo-50 rounded-lg max-md:px-5"},A.createElement("img",{loading:"lazy",src:t,alt:l||"",className:"object-contain shrink-0 aspect-square w-[26px]"}),l&&A.createElement("div",{className:"basis-auto text-sm hidden md:block ltr:text-left rtl:text-right"},l)),de="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvIE1peGVyIFRvb2xzIC0tPgo8c3ZnIHdpZHRoPSI4MDBweCIgaGVpZ2h0PSI4MDBweCIgdmlld0JveD0iLTMgMCAyNjIgMjYyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHByZXNlcnZlQXNwZWN0UmF0aW89InhNaWRZTWlkIj48cGF0aCBkPSJNMjU1Ljg3OCAxMzMuNDUxYzAtMTAuNzM0LS44NzEtMTguNTY3LTIuNzU2LTI2LjY5SDEzMC41NXY0OC40NDhoNzEuOTQ3Yy0xLjQ1IDEyLjA0LTkuMjgzIDMwLjE3Mi0yNi42OSA0Mi4zNTZsLS4yNDQgMS42MjIgMzguNzU1IDMwLjAyMyAyLjY4NS4yNjhjMjQuNjU5LTIyLjc3NCAzOC44NzUtNTYuMjgyIDM4Ljg3NS05Ni4wMjciIGZpbGw9IiM0Mjg1RjQiLz48cGF0aCBkPSJNMTMwLjU1IDI2MS4xYzM1LjI0OCAwIDY0LjgzO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I4MDBweCIgaGVpZ2h0PSI4MDBweCIgdmlld0JveD0iMCAwIDE2IDE2IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiPjxwYXRoIGZpbGw9IiNGMzUzMjUiIGQ9Ik0xIDFoNi41djYuNUgxVjF6Ii8+PHBhdGggZmlsbD0iIzgxQkMwNiIgZD0iTTguNSAxSDE1djYuNUg4LjVWMXoiLz48cGF0aCBmaWxsPSIjMDVBNkYwIiBkPSJNMSA4LjVoNi41VjE1SDFWOC41eiIvPjxwYXRoIGZpbGw9IiNGRkJBMDgiIGQ9Ik04LjUgOC41SDE1VjE1SDguNVY4LjV6Ii8+PC9zdmc+";function Z(t,l,r){return t?t.startsWith(`${l}-`)?t:t.startsWith("#")?`${t}`:r:r}function J(t,l){const r=(l==null?void 0:l.bg)||"bg-sky-500",s=(l==null?void 0:l.text)||"text-gray-800",n=(l==null?void 0:l.border)||"border-gray-300",a=(l==null?void 0:l.fill)||"fill-current",o=(l==null?void 0:l.stroke)||"stroke-current";return{bgClass:Z(t.bg??"","bg",r),textClass:Z(t.text??"","text",s),borderClass:Z(t.border??"","border",n),fillClass:Z(t.fill??"","fill",a),strokeClass:Z(t.stroke??"","stroke",o)}}const _=({message:t,dismissAfterMs:l=4e3})=>{const r=F.useT("authLib"),[s,n]=e.useState(!1);return e.useEffect(()=>{if(n(!!t),t&&l>0){const a=window.setTimeout(()=>n(!1),l);return()=>window.clearTimeout(a)}},[t,l]),!s||!t?null:e.createElement("div",{role:"alert","aria-live":"assertive",className:`
|
|
40
10
|
relative isolate flex w-full max-w-md items-start gap-2 overflow-hidden
|
|
41
11
|
rounded-lg border border-red-300 bg-red-50/80 p-4 pr-6 text-sm text-red-800
|
|
42
12
|
shadow-lg backdrop-blur
|
|
43
13
|
transition-all duration-300 ease-out
|
|
44
|
-
${
|
|
45
|
-
`},e.createElement("span",{className:"absolute ltr:left-0 rtl:right-0 top-0 h-full w-1 bg-gradient-to-b from-red-500 to-red-400"}),e.createElement(
|
|
14
|
+
${s?"translate-y-0 opacity-100":"-translate-y-2 opacity-0"}
|
|
15
|
+
`},e.createElement("span",{className:"absolute ltr:left-0 rtl:right-0 top-0 h-full w-1 bg-gradient-to-b from-red-500 to-red-400"}),e.createElement(oe.AlertTriangle,{className:"mt-0.5 h-5 w-5 flex-none"}),e.createElement("span",{className:"grow leading-5 ltr:text-left rtl:text-right"},t),e.createElement("button",{onClick:()=>n(!1),"aria-label":r("inlineError.dismiss"),className:`
|
|
46
16
|
absolute ltr:right-2 rtl:left-2 top-2 rounded p-1 text-red-600/70
|
|
47
17
|
hover:bg-red-100 hover:text-red-700 focus:outline-none
|
|
48
18
|
focus-visible:ring focus-visible:ring-red-500/50
|
|
49
|
-
`},e.createElement(ye,{className:"h-4 w-4"})))},Ee=()=>{const t=O.useT("authLib"),l=p.useNavigate(),n=p.useLocation(),{brandName:r=t("brandName",{defaultValue:"MyBrand"}),colors:o={bg:"bg-sky-500",text:"text-white",border:"border-sky-500"},logoUrl:s,oauthProviders:a=[],illustrationUrl:c=t("community.illustrationUrl",{defaultValue:"https://cdn.builder.io/api/v1/image/assets/TEMP/35ba84b8335fda2819c3a14ea3d00321a0fd0e79e571caa31108468010868ca5?placeholderIfAbsent=true&apiKey=a460e9a46e514356ac1106eada03046c"}),communityContent:i={title:t("community.title"),description:t("community.description")},baseUrl:u}=ee(),{login:b}=j(),[w,N]=e.useState(""),[C,v]=e.useState(""),[h,g]=e.useState(!1),[k,d]=e.useState(null),M={google:{icon:re,label:t("social.google")},microsoft:{icon:ne,label:t("social.microsoft")}},y=a.filter(x=>x in M).map(x=>({id:x,icon:M[x].icon,label:M[x].label})),{bgClass:I,textClass:T,borderClass:A}=se(o),U=`${I} bg-gradient-to-r from-white/10 via-white/0 to-white/0`;async function F(x){var $;if(x.preventDefault(),!h){d(null),g(!0);try{await b({email:w,password:C})}catch(P){(($=P==null?void 0:P.response)==null?void 0:$.status)===401?d(t("errors.invalidCredentials")):d(t("errors.generic"))}finally{g(!1)}}}function B(x){var P,f,D;if(!u){console.error("Auth baseUrl is not configured.");return}const $=((f=(P=n.state)==null?void 0:P.from)==null?void 0:f.pathname)||((D=n.state)==null?void 0:D.from)||"/";if(sessionStorage.setItem("postLoginRedirect",$),x==="google"){const S="/oauth/google/callback",L=`${window.location.origin}${S}`,E=new URL(`${u}/auth/google`);E.searchParams.set("redirect",L),window.location.href=E.toString();return}if(x==="microsoft"){const S="/oauth/microsoft/callback",L=`${window.location.origin}${S}`,E=new URL(`${u}/auth/microsoft`);E.searchParams.set("redirect",L),window.location.href=E.toString();return}}const J=e.createElement("svg",{className:"h-4 w-4 animate-spin stroke-current",viewBox:"0 0 24 24",fill:"none"},e.createElement("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",strokeWidth:"4"}),e.createElement("path",{className:"opacity-75",d:"M4 12a8 8 0 018-8",strokeWidth:"4",strokeLinecap:"round"}));return e.createElement("div",{className:`flex items-center justify-center min-h-screen p-4 ${U}`},e.createElement("div",{className:"flex w-full max-w-5xl bg-white rounded-2xl shadow-2xl overflow-hidden"},e.createElement("div",{className:`hidden md:flex md:w-1/2 p-12 flex-col justify-between text-white ${I}`},e.createElement("div",null,s?e.createElement("div",{className:"flex items-center gap-4"},e.createElement("img",{loading:"lazy",src:s,alt:"Brand Logo",className:"bg-white h-8 md:h-22 rounded-lg"}),e.createElement("h2",{className:"text-sm md:text-2xl font-bold uppercase"},r)):e.createElement("h2",{className:"text-sm md:text-2xl font-bold"},r)),e.createElement("div",{className:"flex-1 space-y-4 mt-6 py-4"},e.createElement("h3",{className:"text-2xl font-semibold leading-tight"},i.title),e.createElement("p",{className:"text-base leading-relaxed opacity-90 ltr:text-left rtl:text-right"},i.description),e.createElement("div",{className:"relative"},e.createElement("div",{className:"absolute -left-4 -top-4 w-20 h-20 bg-white/20 rounded-full blur-xl"}),e.createElement("div",{className:"absolute -right-4 -bottom-4 w-20 h-20 bg-white/20 rounded-full blur-xl"}),e.createElement("img",{loading:"lazy",src:c,alt:"Sign in illustration",className:"max-w-sm w-full mx-auto rounded-lg shadow-lg transform hover:scale-105 transition-transform duration-300 p-6"})))),e.createElement("div",{className:"w-full md:w-1/2 p-4 md:p-8 m-auto"},e.createElement("div",{className:"flex flex-col md:flex-row justify-between items-center mb-8"},e.createElement("div",{className:"flex items-center justify-center md:hidden mb-5"},s?e.createElement("img",{loading:"lazy",src:s,alt:"Brand Logo",className:`h-22 rounded-full border ${A}`}):e.createElement("h2",{className:"text-2xl font-bold"},r)),e.createElement("div",{className:"w-full md:w-auto mb-4 md:mb-0 text-center md:text-left ltr:text-center rtl:text-center md:ltr:text-left md:rtl:text-right"},e.createElement("p",{className:"text-sm md:text-lg"},t("SignInPage.welcome")," ",e.createElement("span",{className:`font-semibold ${T} uppercase`},r)),e.createElement("h1",{className:"text-2xl md:text-4xl font-bold text-gray-800"},t("SignInPage.signIn"))),e.createElement("div",{className:"text-sm text-gray-500 text-center md:text-right"},t("SignInPage.noAccount"),e.createElement("br",null),e.createElement("button",{type:"button",onClick:()=>l("/signup"),className:T},t("SignInPage.signUp")))),k&&e.createElement(ie,{message:k}),e.createElement("form",{className:"space-y-6",onSubmit:F},e.createElement(W,{label:t("form.emailLabel"),type:"email",placeholder:t("form.emailPlaceholder"),color:A,value:w,onChange:N}),e.createElement(W,{label:t("form.passwordLabel"),type:"password",placeholder:t("form.passwordPlaceholder"),color:A,value:C,onChange:v}),e.createElement("div",{className:"ltr:text-right rtl:text-left"},e.createElement("button",{className:`text-sm ${T}`},t("SignInPage.forgotPassword"))),e.createElement("button",{type:"submit",disabled:h,className:`relative flex w-full items-center justify-center gap-2 py-3 rounded-lg font-medium transition-colors ${h?"opacity-60 cursor-not-allowed":""} ${I} text-white`},h&&J,t(h?"SignInPage.signInSubmitting":"SignInPage.signIn")),y.length>0&&e.createElement(e.Fragment,null,e.createElement("div",{className:"flex items-center pt-2"},e.createElement("div",{className:`flex-grow h-px ${I}`}),e.createElement("span",{className:`${T} mx-3 text-sm`},t("SignInPage.orLoginWith")),e.createElement("div",{className:`flex-grow h-px ${I}`})),e.createElement("div",{className:"flex gap-3 mb-6 justify-center md:justify-start"},y.map(x=>e.createElement("button",{key:x.id,type:"button",onClick:()=>B(x.id),className:"flex-1"},e.createElement(le,{icon:x.icon,label:x.label})))))))))},Ne=()=>{const t=O.useT("authLib"),l=p.useNavigate(),n=p.useLocation(),{brandName:r=t("brandName",{defaultValue:"MyBrand"}),colors:o={bg:"bg-sky-500",text:"text-white",border:"border-sky-500"},logoUrl:s,oauthProviders:a=[],illustrationUrl:c=t("community.illustrationUrl",{defaultValue:"https://cdn.builder.io/api/v1/image/assets/TEMP/35ba84b8335fda2819c3a14ea3d00321a0fd0e79e571caa31108468010868ca5?placeholderIfAbsent=true&apiKey=a460e9a46e514356ac1106eada03046c"}),communityContent:i={title:t("community.title"),description:t("community.description")},baseUrl:u}=ee(),{login:b,api:w}=j(),[N,C]=e.useState(""),[v,h]=e.useState(""),[g,k]=e.useState(""),[d,M]=e.useState(!1),[y,I]=e.useState(null),T={google:{icon:re,label:t("social.google")},microsoft:{icon:ne,label:t("social.microsoft")}},A=a.filter(f=>f in T).map(f=>({id:f,icon:T[f].icon,label:T[f].label})),{bgClass:U,textClass:F,borderClass:B}=se(o),J=`${U} bg-gradient-to-r from-white/10 via-white/0 to-white/0`;async function x(f){var D,S,L;if(f.preventDefault(),!d){I(null),M(!0);try{await w.post("/auth/clients/register",{email:v,password:g,name:N||void 0}),await b({email:v,password:g})}catch(E){const V=(D=E==null?void 0:E.response)==null?void 0:D.status;I(V===400?((L=(S=E==null?void 0:E.response)==null?void 0:S.data)==null?void 0:L.message)||t("errors.invalidData",{defaultValue:"Please check the fields and try again."}):V===409?t("errors.emailInUse",{defaultValue:"This email is already in use."}):t("errors.generic",{defaultValue:"Something went wrong. Please try again."}))}finally{M(!1)}}}function $(f){var S,L,E;if(!u){console.error("Auth baseUrl is not configured.");return}const D=((L=(S=n.state)==null?void 0:S.from)==null?void 0:L.pathname)||((E=n.state)==null?void 0:E.from)||"/";if(sessionStorage.setItem("postLoginRedirect",D),f==="google"){const V="/oauth/google/callback",K=`${window.location.origin}${V}`,G=new URL(`${u}/auth/google`);G.searchParams.set("redirect",K),window.location.href=G.toString();return}if(f==="microsoft"){const V="/oauth/microsoft/callback",K=`${window.location.origin}${V}`,G=new URL(`${u}/auth/microsoft`);G.searchParams.set("redirect",K),window.location.href=G.toString();return}}const P=e.createElement("svg",{className:"h-4 w-4 animate-spin stroke-current",viewBox:"0 0 24 24",fill:"none"},e.createElement("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",strokeWidth:"4"}),e.createElement("path",{className:"opacity-75",d:"M4 12a8 8 0 018-8",strokeWidth:"4",strokeLinecap:"round"}));return e.createElement("div",{className:`flex items-center justify-center min-h-screen p-4 ${J}`},e.createElement("div",{className:"flex w-full max-w-5xl bg-white rounded-2xl shadow-2xl overflow-hidden"},e.createElement("div",{className:`hidden md:flex md:w-1/2 p-12 flex-col justify-between text-white ${U}`},e.createElement("div",null,s?e.createElement("div",{className:"flex items-center gap-4"},e.createElement("img",{loading:"lazy",src:s,alt:"Brand Logo",className:"bg-white h-8 md:h-22 rounded-lg"}),e.createElement("h2",{className:"text-sm md:text-2xl font-bold uppercase"},r)):e.createElement("h2",{className:"text-sm md:text-2xl font-bold"},r)),e.createElement("div",{className:"flex-1 space-y-4 mt-6 py-4"},e.createElement("h3",{className:"text-2xl font-semibold leading-tight"},i.title),e.createElement("p",{className:"text-base leading-relaxed opacity-90 ltr:text-left rtl:text-right"},i.description),e.createElement("div",{className:"relative"},e.createElement("div",{className:"absolute -left-4 -top-4 w-20 h-20 bg-white/20 rounded-full blur-xl"}),e.createElement("div",{className:"absolute -right-4 -bottom-4 w-20 h-20 bg-white/20 rounded-full blur-xl"}),e.createElement("img",{loading:"lazy",src:c,alt:"Sign up illustration",className:"max-w-sm w-full mx-auto rounded-lg shadow-lg transform hover:scale-105 transition-transform duration-300 p-6"})))),e.createElement("div",{className:"w-full md:w-1/2 p-4 md:p-8 m-auto"},e.createElement("div",{className:"flex flex-col md:flex-row justify-between items-center mb-8"},e.createElement("div",{className:"flex items-center justify-center md:hidden mb-5"},s?e.createElement("img",{loading:"lazy",src:s,alt:"Brand Logo",className:`h-22 rounded-full border ${B}`}):e.createElement("h2",{className:"text-2xl font-bold"},r)),e.createElement("div",{className:"w-full md:w-auto mb-4 md:mb-0 text-center md:text-left ltr:text-center rtl:text-center md:ltr:text-left md:rtl:text-right"},e.createElement("p",{className:"text-sm md:text-lg"},t("SignUpPage.welcome",{defaultValue:"Join"})," ",e.createElement("span",{className:`font-semibold ${F} uppercase`},r)),e.createElement("h1",{className:"text-2xl md:text-4xl font-bold text-gray-800"},t("SignUpPage.signUp",{defaultValue:"Sign up"}))),e.createElement("div",{className:"text-sm text-gray-500 text-center md:text-right"},t("SignUpPage.alreadyHaveAccount",{defaultValue:"Already have an account?"}),e.createElement("br",null),e.createElement("button",{type:"button",onClick:()=>l("/login"),className:F},t("SignUpPage.signIn",{defaultValue:"Sign in"})))),y&&e.createElement(ie,{message:y}),e.createElement("form",{className:"space-y-6",onSubmit:x},e.createElement(W,{label:t("form.nameLabel",{defaultValue:"Name"}),type:"text",placeholder:t("form.namePlaceholder",{defaultValue:"Enter your name"}),color:B,value:N,onChange:C}),e.createElement(W,{label:t("form.emailLabel"),type:"email",placeholder:t("form.emailPlaceholder"),color:B,value:v,onChange:h}),e.createElement(W,{label:t("form.passwordLabel"),type:"password",placeholder:t("form.passwordPlaceholder"),color:B,value:g,onChange:k}),e.createElement("button",{type:"submit",disabled:d,className:`relative flex w-full items-center justify-center gap-2 py-3 rounded-lg font-medium transition-colors ${d?"opacity-60 cursor-not-allowed":""} ${U} text-white`},d&&P,d?t("SignUpPage.signUpSubmitting",{defaultValue:"Creating account..."}):t("SignUpPage.signUp",{defaultValue:"Sign up"})),A.length>0&&e.createElement(e.Fragment,null,e.createElement("div",{className:"flex items-center pt-2"},e.createElement("div",{className:`flex-grow h-px ${U}`}),e.createElement("span",{className:`${F} mx-3 text-sm`},t("SignUpPage.orContinueWith",{defaultValue:"Or continue with"})),e.createElement("div",{className:`flex-grow h-px ${U}`})),e.createElement("div",{className:"flex gap-3 mb-6 justify-center md:justify-start"},A.map(f=>e.createElement("button",{key:f.id,type:"button",onClick:()=>$(f.id),className:"flex-1"},e.createElement(le,{icon:f.icon,label:f.label})))))))))},ce=()=>(e.useEffect(()=>{const t=new URLSearchParams(window.location.search),l=t.get("accessToken"),n=t.get("refreshToken");l&&localStorage.setItem("authToken",l),n&&localStorage.setItem("refreshToken",n);const r=sessionStorage.getItem("postLoginRedirect")||"/";sessionStorage.removeItem("postLoginRedirect"),window.location.replace(r)},[]),e.createElement("div",{className:"flex items-center justify-center min-h-screen text-gray-700"},"Finishing Google sign-in…")),ve=({children:t})=>{const{isAuthenticated:l}=j(),n=p.useLocation();return l?t:e.createElement(p.Navigate,{to:"/login",state:{from:n},replace:!0})},Me=({config:t,children:l})=>{const n=p.useNavigate(),[r,o]=e.useState(()=>localStorage.getItem("authToken")),[s,a]=e.useState(null),[c,i]=e.useState(!0),[u,b]=e.useState(!1);async function w(){try{await N.post("/auth/logout")}catch(h){console.warn("Logout endpoint failed, proceeding with local logout:",h)}o(null),a(null),localStorage.removeItem("authToken"),sessionStorage.clear(),b(!1),n("/login",{replace:!0})}const N=e.useMemo(()=>{const h=H.create({baseURL:t.baseUrl,withCredentials:!0});return fe(h,{baseUrl:t.baseUrl,getAccessToken:()=>r,setAccessToken:g=>o(g),logout:()=>b(!0)}),h},[t.baseUrl,r]);e.useEffect(()=>{(async()=>{if(r){a(Q(r)),i(!1);return}try{const{data:g}=await H.post(`${t.baseUrl}/auth/refresh-token`,{},{withCredentials:!0});o(g.accessToken),a(Q(g.accessToken)),localStorage.setItem("authToken",g.accessToken)}catch{}finally{i(!1)}})()},[r,t.baseUrl]);async function C(h){const{data:g}=await N.post("/auth/clients/login",h);o(g.accessToken),a(Q(g.accessToken)),localStorage.setItem("authToken",g.accessToken),ge(),n("/",{replace:!0})}const v=e.useMemo(()=>({isAuthenticated:!!r,accessToken:r,user:s,login:C,logout:w,api:N,setUser:a}),[r,s,N]);return e.createElement(R.Provider,{value:t},e.createElement(te.Provider,{value:v},e.createElement(p.Routes,null,e.createElement(p.Route,{path:"login",element:r?e.createElement(p.Navigate,{to:"/",replace:!0}):e.createElement(Ee,{baseUrl:t.baseUrl,colors:t.colors})}),e.createElement(p.Route,{path:"signup",element:r?e.createElement(p.Navigate,{to:"/",replace:!0}):e.createElement(Ne,null)}),e.createElement(p.Route,{path:"oauth/google/callback",element:e.createElement(ce,null)}),e.createElement(p.Route,{path:"/oauth/microsoft/callback",element:e.createElement(ce,null)}),e.createElement(p.Route,{path:"*",element:e.createElement(ve,null,l)})),u&&e.createElement(he,{onConfirm:w})))};function X(...t){const{user:l}=j(),n=(l==null?void 0:l.roles)??[];return t.some(r=>n.includes(r))}function Ie(t){const{user:l}=j();return(l==null?void 0:l.modules.includes(t))??!1}function Y(...t){const{user:l}=j(),n=(l==null?void 0:l.permissions)??[];return t.every(r=>n.includes(r))}const ke=({children:t,fallbackpermessions:l=[],anyPermessions:n=[],fallbackRoles:r=["super-admin"],redirectTo:o="/dashboard"})=>{if(r.some(i=>X(i)))return e.createElement(e.Fragment,null,t);const a=l.length===0||l.every(i=>Y(i)),c=n.length===0||n.some(i=>Y(i));return a&&c?e.createElement(e.Fragment,null,t):e.createElement(p.Navigate,{to:o,replace:!0})},_=e.createContext({}),Se=_.Provider;function Le(t,l){var o,s,a;const r=(o=e.useContext(_)[t])==null?void 0:o[l];return r?!!((s=r.perms)!=null&&s.some(c=>Y(c))||(a=r.fallbackRoles)!=null&&a.some(c=>X(c))):!1}const je=()=>{const{user:t,api:l,setUser:n}=j(),[r,o]=e.useState((t==null?void 0:t.name)??""),[s,a]=e.useState((t==null?void 0:t.email)??""),[c,i]=e.useState(!1),[u,b]=e.useState(!1),[w,N]=e.useState({open:!1,type:"success",title:"",message:""}),C="+971 50 827 8229";e.useEffect(()=>{if(!w.open)return;const d=window.setTimeout(()=>N(M=>({...M,open:!1})),3e3);return()=>window.clearTimeout(d)},[w.open]),e.useEffect(()=>{let d=!1;async function M(){try{const{data:y}=await l.get("/auth/client/me");if(d)return;n(y),o((y==null?void 0:y.name)??""),a((y==null?void 0:y.email)??"")}catch(y){console.error("Failed to load profile details:",y)}}return M(),()=>{d=!0}},[l,n]);const v=e.useMemo(()=>(r||(t==null?void 0:t.name)||(t==null?void 0:t.email)||"").trim(),[r,t==null?void 0:t.name,t==null?void 0:t.email]),h=e.useMemo(()=>v.charAt(0).toUpperCase()||"?",[v]);async function g(){if(t){b(!0);try{await l.patch("/auth/client/me",{name:r}),n({...t,name:r}),i(!1),N({open:!0,type:"success",title:"Changes saved",message:"Your profile was updated successfully."})}catch(d){console.error("Failed to update profile:",d),N({open:!0,type:"error",title:"Save failed",message:"Failed to save changes. Please try again."})}finally{b(!1)}}}if(!t)return e.createElement("p",{className:"text-sm text-gray-500"},"No user data available.");const k=w.type==="success";return e.createElement("div",{className:"max-w-3xl mx-auto"},w.open&&e.createElement("div",{className:"fixed top-6 right-6 z-[999999] flex items-center gap-3 rounded-xl border bg-white px-4 py-3 shadow-lg",role:"status","aria-live":"polite",style:{borderColor:k?"#BBF7D0":"#FECACA"}},e.createElement("div",{className:"flex h-9 w-9 items-center justify-center rounded-full",style:{backgroundColor:k?"#ECFDF5":"#FEF2F2"}},k?e.createElement("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"text-green-600"},e.createElement("path",{d:"M20 6L9 17L4 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})):e.createElement("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"text-red-600"},e.createElement("path",{d:"M12 9V13",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),e.createElement("path",{d:"M12 17H12.01",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),e.createElement("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0Z",stroke:"currentColor",strokeWidth:"2",strokeLinejoin:"round"}))),e.createElement("div",{className:"flex flex-col"},e.createElement("span",{className:"text-sm font-semibold",style:{color:k?"#15803D":"#B91C1C"}},w.title),w.message&&e.createElement("span",{className:"text-xs text-gray-500"},w.message)),e.createElement("button",{type:"button",onClick:()=>N(d=>({...d,open:!1})),className:"ml-2 rounded-md px-2 py-1 text-gray-500 hover:bg-gray-100","aria-label":"Close",title:"Close"},e.createElement("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("path",{d:"M18 6L6 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),e.createElement("path",{d:"M6 6L18 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})))),e.createElement("div",{className:"rounded-2xl border border-gray-200 bg-white shadow-sm"},e.createElement("div",{className:"px-6 pt-6 pb-4"},e.createElement("div",{className:"flex items-center justify-between"},e.createElement("div",{className:"flex items-center gap-4"},e.createElement("div",{className:"relative"},e.createElement("div",{className:"h-16 w-16 rounded-full bg-blue-600 flex items-center justify-center text-white text-2xl font-semibold"},h),e.createElement("button",{type:"button",className:"absolute -bottom-1 -right-1 h-8 w-8 rounded-full border border-gray-200 bg-white shadow-sm flex items-center justify-center hover:bg-gray-50",title:"Change avatar"},e.createElement("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("path",{d:"M12 20H21",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),e.createElement("path",{d:"M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5Z",stroke:"currentColor",strokeWidth:"2",strokeLinejoin:"round"})))),e.createElement("div",null,e.createElement("h1",{className:"text-2xl font-semibold"},"My Profile"),e.createElement("p",{className:"text-sm text-gray-500"},"Personal details"))),c?e.createElement("button",{type:"button",onClick:g,disabled:u,className:"rounded-full border border-blue-200 bg-blue-50 px-4 py-2 text-sm font-medium text-blue-700 hover:bg-blue-100 disabled:opacity-60"},u?"Saving…":"Save changes"):e.createElement("button",{type:"button",onClick:()=>i(!0),title:"Edit profile",className:"h-9 w-9 rounded-full border border-gray-200 bg-white shadow-sm flex items-center justify-center hover:bg-gray-50"},e.createElement("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("path",{d:"M12 20H21",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),e.createElement("path",{d:"M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5Z",stroke:"currentColor",strokeWidth:"2",strokeLinejoin:"round"}))))),e.createElement("div",{className:"px-6 pb-6 border-t border-gray-100 pt-6"},e.createElement("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5"},e.createElement("div",null,e.createElement("label",{className:"block text-xs font-medium text-gray-500 mb-2"},"Username"),e.createElement("input",{type:"text",value:r,disabled:!c||u,onChange:d=>o(d.target.value),className:`w-full rounded-lg border px-3 py-2 text-sm outline-none ${c?"border-gray-300 bg-white focus:border-blue-500 focus:ring-2 focus:ring-blue-100":"border-gray-200 bg-gray-50 text-gray-700"}`})),e.createElement("div",null,e.createElement("label",{className:"block text-xs font-medium text-gray-500 mb-2"},"Email ID"),e.createElement("input",{type:"email",value:s,disabled:!0,className:"w-full rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-sm text-gray-700 cursor-not-allowed"})),e.createElement("div",null,e.createElement("label",{className:"block text-xs font-medium text-gray-500 mb-2"},"Mobile number"),e.createElement("input",{type:"text",value:C,disabled:!0,className:"w-full rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-sm text-gray-700 cursor-not-allowed"}))),c&&e.createElement("button",{type:"button",disabled:u,onClick:()=>{i(!1),o((t==null?void 0:t.name)??"")},className:"mt-6 text-sm font-medium text-gray-600 hover:text-gray-900"},"Cancel"))))};m.AuthProvider=Me,m.ProfilePage=je,m.RbacContext=_,m.RbacProvider=Se,m.RequirePermissions=ke,m.useAuthState=j,m.useCan=Y,m.useGrant=Le,m.useHasModule=Ie,m.useHasRole=X,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
|
19
|
+
`},e.createElement(oe.X,{className:"h-4 w-4"})))},Ee=()=>{const t=F.useT("authLib"),l=h.useNavigate(),r=h.useLocation(),{brandName:s=t("brandName",{defaultValue:"MyBrand"}),colors:n={bg:"bg-sky-500",text:"text-white",border:"border-sky-500"},logoUrl:a,oauthProviders:o=[],illustrationUrl:m=t("community.illustrationUrl",{defaultValue:"https://cdn.builder.io/api/v1/image/assets/TEMP/35ba84b8335fda2819c3a14ea3d00321a0fd0e79e571caa31108468010868ca5?placeholderIfAbsent=true&apiKey=a460e9a46e514356ac1106eada03046c"}),communityContent:i={title:t("community.title"),description:t("community.description")},baseUrl:d}=X(),{login:w}=L(),[p,c]=e.useState(""),[S,v]=e.useState(""),[b,u]=e.useState(!1),[k,g]=e.useState(null),y={google:{icon:de,label:t("social.google")},microsoft:{icon:ue,label:t("social.microsoft")}},x=o.filter(E=>E in y).map(E=>({id:E,icon:y[E].icon,label:y[E].label})),{bgClass:j,textClass:M,borderClass:z}=J(n),D=`${j} bg-gradient-to-r from-white/10 via-white/0 to-white/0`;async function C(E){var B;if(E.preventDefault(),!b){g(null),u(!0);try{await w({email:p,password:S})}catch(I){((B=I==null?void 0:I.response)==null?void 0:B.status)===401?g(t("errors.invalidCredentials")):g(t("errors.generic"))}finally{u(!1)}}}function V(E){var I,W,T;if(!d){console.error("Auth baseUrl is not configured.");return}const B=((W=(I=r.state)==null?void 0:I.from)==null?void 0:W.pathname)||((T=r.state)==null?void 0:T.from)||"/";if(sessionStorage.setItem("postLoginRedirect",B),E==="google"){const G="/oauth/google/callback",Y=`${window.location.origin}${G}`,$=new URL(`${d}/auth/google`);$.searchParams.set("redirect",Y),window.location.href=$.toString();return}if(E==="microsoft"){const G="/oauth/microsoft/callback",Y=`${window.location.origin}${G}`,$=new URL(`${d}/auth/microsoft`);$.searchParams.set("redirect",Y),window.location.href=$.toString();return}}const ae=e.createElement("svg",{className:"h-4 w-4 animate-spin stroke-current",viewBox:"0 0 24 24",fill:"none"},e.createElement("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",strokeWidth:"4"}),e.createElement("path",{className:"opacity-75",d:"M4 12a8 8 0 018-8",strokeWidth:"4",strokeLinecap:"round"}));return e.createElement("div",{className:`flex items-center justify-center min-h-screen p-4 ${D}`},e.createElement("div",{className:"flex w-full max-w-5xl bg-white rounded-2xl shadow-2xl overflow-hidden"},e.createElement("div",{className:`hidden md:flex md:w-1/2 p-12 flex-col justify-between text-white ${j}`},e.createElement("div",null,a?e.createElement("div",{className:"flex items-center gap-4"},e.createElement("img",{loading:"lazy",src:a,alt:"Brand Logo",className:"bg-white h-8 md:h-22 rounded-lg"}),e.createElement("h2",{className:"text-sm md:text-2xl font-bold uppercase"},s)):e.createElement("h2",{className:"text-sm md:text-2xl font-bold"},s)),e.createElement("div",{className:"flex-1 space-y-4 mt-6 py-4"},e.createElement("h3",{className:"text-2xl font-semibold leading-tight"},i.title),e.createElement("p",{className:"text-base leading-relaxed opacity-90 ltr:text-left rtl:text-right"},i.description),e.createElement("div",{className:"relative"},e.createElement("div",{className:"absolute -left-4 -top-4 w-20 h-20 bg-white/20 rounded-full blur-xl"}),e.createElement("div",{className:"absolute -right-4 -bottom-4 w-20 h-20 bg-white/20 rounded-full blur-xl"}),e.createElement("img",{loading:"lazy",src:m,alt:"Sign in illustration",className:"max-w-sm w-full mx-auto rounded-lg shadow-lg transform hover:scale-105 transition-transform duration-300 p-6"})))),e.createElement("div",{className:"w-full md:w-1/2 p-4 md:p-8 m-auto"},e.createElement("div",{className:"flex flex-col md:flex-row justify-between items-center mb-8"},e.createElement("div",{className:"flex items-center justify-center md:hidden mb-5"},a?e.createElement("img",{loading:"lazy",src:a,alt:"Brand Logo",className:`h-22 rounded-full border ${z}`}):e.createElement("h2",{className:"text-2xl font-bold"},s)),e.createElement("div",{className:"w-full md:w-auto mb-4 md:mb-0 text-center md:text-left ltr:text-center rtl:text-center md:ltr:text-left md:rtl:text-right"},e.createElement("p",{className:"text-sm md:text-lg"},t("SignInPage.welcome")," ",e.createElement("span",{className:`font-semibold ${M} uppercase`},s)),e.createElement("h1",{className:"text-2xl md:text-4xl font-bold text-gray-800"},t("SignInPage.signIn"))),e.createElement("div",{className:"text-sm text-gray-500 text-center md:text-right"},t("SignInPage.noAccount"),e.createElement("br",null),e.createElement("button",{type:"button",onClick:()=>l("/signup"),className:M},t("SignInPage.signUp")))),k&&e.createElement(_,{message:k}),e.createElement("form",{className:"space-y-6",onSubmit:C},e.createElement(P,{label:t("form.emailLabel"),type:"email",placeholder:t("form.emailPlaceholder"),color:z,value:p,onChange:c}),e.createElement(P,{label:t("form.passwordLabel"),type:"password",placeholder:t("form.passwordPlaceholder"),color:z,value:S,onChange:v}),e.createElement("div",{className:"ltr:text-right rtl:text-left"},e.createElement(h.Link,{to:"/forgot-password",className:M},t("SignInPage.forgotPassword"))),e.createElement("button",{type:"submit",disabled:b,className:`relative flex w-full items-center justify-center gap-2 py-3 rounded-lg font-medium transition-colors ${b?"opacity-60 cursor-not-allowed":""} ${j} text-white`},b&&ae,t(b?"SignInPage.signInSubmitting":"SignInPage.signIn")),x.length>0&&e.createElement(e.Fragment,null,e.createElement("div",{className:"flex items-center pt-2"},e.createElement("div",{className:`flex-grow h-px ${j}`}),e.createElement("span",{className:`${M} mx-3 text-sm`},t("SignInPage.orLoginWith")),e.createElement("div",{className:`flex-grow h-px ${j}`})),e.createElement("div",{className:"flex gap-3 mb-6 justify-center md:justify-start"},x.map(E=>e.createElement("button",{key:E.id,type:"button",onClick:()=>V(E.id),className:"flex-1"},e.createElement(me,{icon:E.icon,label:E.label})))))))))},ye=()=>{const t=F.useT("authLib"),l=h.useNavigate(),r=h.useLocation(),{brandName:s=t("brandName",{defaultValue:"MyBrand"}),colors:n={bg:"bg-sky-500",text:"text-white",border:"border-sky-500"},logoUrl:a,oauthProviders:o=[],illustrationUrl:m=t("community.illustrationUrl",{defaultValue:"https://cdn.builder.io/api/v1/image/assets/TEMP/35ba84b8335fda2819c3a14ea3d00321a0fd0e79e571caa31108468010868ca5?placeholderIfAbsent=true&apiKey=a460e9a46e514356ac1106eada03046c"}),communityContent:i={title:t("community.title"),description:t("community.description")},baseUrl:d}=X(),{login:w,api:p}=L(),[c,S]=e.useState(""),[v,b]=e.useState(""),[u,k]=e.useState(""),[g,y]=e.useState(""),[x,j]=e.useState(""),[M,z]=e.useState(!1),[D,C]=e.useState(null),[V,ae]=e.useState(!1),E={google:{icon:de,label:t("social.google")},microsoft:{icon:ue,label:t("social.microsoft")}},B=o.filter(N=>N in E).map(N=>({id:N,icon:E[N].icon,label:E[N].label})),{bgClass:I,textClass:W,borderClass:T}=J(n),G=`${I} bg-gradient-to-r from-white/10 via-white/0 to-white/0`;async function Y(N){var R,H,q;if(N.preventDefault(),!M){C(null),z(!0);try{await p.post("/api/auth/register",{fullname:{fname:c,lname:v},username:u,email:g,password:x}),await w({email:g,password:x})}catch(U){const O=(R=U==null?void 0:U.response)==null?void 0:R.status;C(O===400?((q=(H=U==null?void 0:U.response)==null?void 0:H.data)==null?void 0:q.message)||t("errors.invalidData",{defaultValue:"Please check the fields and try again."}):O===409?t("errors.emailInUse",{defaultValue:"This email is already in use."}):t("errors.generic",{defaultValue:"Something went wrong. Please try again."}))}finally{z(!1)}}}function $(N){var H,q,U;if(!d){console.error("Auth baseUrl is not configured.");return}const R=((q=(H=r.state)==null?void 0:H.from)==null?void 0:q.pathname)||((U=r.state)==null?void 0:U.from)||"/";if(sessionStorage.setItem("postLoginRedirect",R),N==="google"){const O="/oauth/google/callback",ne=`${window.location.origin}${O}`,Q=new URL(`${d}/auth/google`);Q.searchParams.set("redirect",ne),window.location.href=Q.toString();return}if(N==="microsoft"){const O="/oauth/microsoft/callback",ne=`${window.location.origin}${O}`,Q=new URL(`${d}/auth/microsoft`);Q.searchParams.set("redirect",ne),window.location.href=Q.toString();return}}const je=e.createElement("svg",{className:"h-4 w-4 animate-spin stroke-current",viewBox:"0 0 24 24",fill:"none"},e.createElement("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",strokeWidth:"4"}),e.createElement("path",{className:"opacity-75",d:"M4 12a8 8 0 018-8",strokeWidth:"4",strokeLinecap:"round"}));return e.createElement("div",{className:`flex items-center justify-center min-h-screen p-4 ${G}`},e.createElement("div",{className:"flex w-full max-w-5xl bg-white rounded-2xl shadow-2xl overflow-hidden"},e.createElement("div",{className:`hidden md:flex md:w-1/2 p-12 flex-col justify-between text-white ${I}`},e.createElement("div",null,a?e.createElement("div",{className:"flex items-center gap-4"},e.createElement("img",{loading:"lazy",src:a,alt:"Brand Logo",className:"bg-white h-8 md:h-22 rounded-lg"}),e.createElement("h2",{className:"text-sm md:text-2xl font-bold uppercase"},s)):e.createElement("h2",{className:"text-sm md:text-2xl font-bold"},s)),e.createElement("div",{className:"flex-1 space-y-4 mt-6 py-4"},e.createElement("h3",{className:"text-2xl font-semibold leading-tight"},i.title),e.createElement("p",{className:"text-base leading-relaxed opacity-90 ltr:text-left rtl:text-right"},i.description),e.createElement("div",{className:"relative"},e.createElement("div",{className:"absolute -left-4 -top-4 w-20 h-20 bg-white/20 rounded-full blur-xl"}),e.createElement("div",{className:"absolute -right-4 -bottom-4 w-20 h-20 bg-white/20 rounded-full blur-xl"}),e.createElement("img",{loading:"lazy",src:m,alt:"Sign up illustration",className:"max-w-sm w-full mx-auto rounded-lg shadow-lg transform hover:scale-105 transition-transform duration-300 p-6"})))),e.createElement("div",{className:"w-full md:w-1/2 p-4 md:p-8 m-auto"},e.createElement("div",{className:"flex flex-col md:flex-row justify-between items-center mb-8"},e.createElement("div",{className:"flex items-center justify-center md:hidden mb-5"},a?e.createElement("img",{loading:"lazy",src:a,alt:"Brand Logo",className:`h-22 rounded-full border ${T}`}):e.createElement("h2",{className:"text-2xl font-bold"},s)),e.createElement("div",{className:"w-full md:w-auto mb-4 md:mb-0 text-center md:text-left ltr:text-center rtl:text-center md:ltr:text-left md:rtl:text-right"},e.createElement("p",{className:"text-sm md:text-lg"},t("SignUpPage.welcome",{defaultValue:"Join"})," ",e.createElement("span",{className:`font-semibold ${W} uppercase`},s)),e.createElement("h1",{className:"text-2xl md:text-4xl font-bold text-gray-800"},t("SignUpPage.signUp",{defaultValue:"Sign up"}))),e.createElement("div",{className:"text-sm text-gray-500 text-center md:text-right"},t("SignUpPage.alreadyHaveAccount",{defaultValue:"Already have an account?"}),e.createElement("br",null),e.createElement("button",{type:"button",onClick:()=>l("/login"),className:W},t("SignUpPage.signIn",{defaultValue:"Sign in"})))),D&&e.createElement(_,{message:D}),e.createElement("form",{className:"space-y-6",onSubmit:Y},e.createElement("div",{className:"flex gap-2"},e.createElement(P,{label:t("form.fnameLabel",{defaultValue:"First Name"}),type:"text",placeholder:t("form.fnamePlaceholder",{defaultValue:"Enter your first name"}),color:T,value:c,onChange:S}),e.createElement(P,{label:t("form.lnameLabel",{defaultValue:"Last Name"}),type:"text",placeholder:t("form.lnamePlaceholder",{defaultValue:"Enter your last name"}),color:T,value:v,onChange:b})),e.createElement(P,{label:t("form.usernameLabel",{defaultValue:"Username"}),type:"text",placeholder:t("form.usernamePlaceholder",{defaultValue:"Choose a username"}),color:T,value:u,onChange:k}),e.createElement(P,{label:t("form.emailLabel"),type:"email",placeholder:t("form.emailPlaceholder"),color:T,value:g,onChange:y}),e.createElement(P,{label:t("form.passwordLabel"),type:"password",placeholder:t("form.passwordPlaceholder"),color:T,value:x,onChange:j}),e.createElement("div",{className:"flex items-center gap-2"},e.createElement("input",{id:"agree",type:"checkbox",checked:V,onChange:N=>ae(N.target.checked),className:"form-checkbox"}),e.createElement("label",{htmlFor:"agree",className:"text-sm"},"I agree to the ",e.createElement("span",{className:"underline cursor-pointer"},"terms and conditions")," (placeholder)")),e.createElement("button",{type:"submit",disabled:M,className:`relative flex w-full items-center justify-center gap-2 py-3 rounded-lg font-medium transition-colors ${M?"opacity-60 cursor-not-allowed":""} ${I} text-white`},M&&je,M?t("SignUpPage.signUpSubmitting",{defaultValue:"Creating account..."}):t("SignUpPage.signUp",{defaultValue:"Sign up"})),B.length>0&&e.createElement(e.Fragment,null,e.createElement("div",{className:"flex items-center pt-2"},e.createElement("div",{className:`flex-grow h-px ${I}`}),e.createElement("span",{className:`${W} mx-3 text-sm`},t("SignUpPage.orContinueWith",{defaultValue:"Or continue with"})),e.createElement("div",{className:`flex-grow h-px ${I}`})),e.createElement("div",{className:"flex gap-3 mb-6 justify-center md:justify-start"},B.map(N=>e.createElement("button",{key:N.id,type:"button",onClick:()=>$(N.id),className:"flex-1"},e.createElement(me,{icon:N.icon,label:N.label})))))))))},ge=()=>(e.useEffect(()=>{const t=new URLSearchParams(window.location.search),l=t.get("accessToken"),r=t.get("refreshToken");l&&localStorage.setItem("authToken",l),r&&localStorage.setItem("refreshToken",r);const s=sessionStorage.getItem("postLoginRedirect")||"/";sessionStorage.removeItem("postLoginRedirect"),window.location.replace(s)},[]),e.createElement("div",{className:"flex items-center justify-center min-h-screen text-gray-700"},"Finishing Google sign-in…")),Ne=()=>{const t=F.useT("authLib"),l=h.useNavigate(),{colors:r,brandName:s=t("brandName",{defaultValue:"MyBrand"}),logoUrl:n}=X(),{api:a}=L(),{bgClass:o,textClass:m,borderClass:i}=J(r),d=`${o} bg-gradient-to-r from-white/10 via-white/0 to-white/0`,[w,p]=e.useState(""),[c,S]=e.useState(!1),[v,b]=e.useState(null),[u,k]=e.useState(!1);async function g(y){if(y.preventDefault(),!c){b(null),S(!0);try{await a.post("/api/auth/forgot-password",{email:w}),k(!0)}catch(x){k(!0),console.error("Forgot password request failed",x)}finally{S(!1)}}}return e.createElement("div",{className:`flex items-center justify-center min-h-screen p-4 ${d}`},e.createElement("div",{className:"flex w-full max-w-xl bg-white rounded-2xl shadow-2xl overflow-hidden"},e.createElement("div",{className:"w-full p-6 md:p-8"},e.createElement("div",{className:"flex items-center justify-between mb-6"},n?e.createElement("img",{loading:"lazy",src:n,alt:"Brand Logo",className:`h-10 rounded-lg border ${i}`}):e.createElement("h2",{className:"text-xl font-bold"},s),e.createElement("button",{type:"button",onClick:()=>l("/login"),className:`text-sm ${m}`},t("ForgotPasswordPage.backToLogin",{defaultValue:"Back to Sign In"}))),e.createElement("h1",{className:"text-2xl md:text-3xl font-bold text-gray-800"},t("ForgotPasswordPage.title",{defaultValue:"Forgot your password?"})),e.createElement("p",{className:"mt-2 text-sm text-gray-600"},t("ForgotPasswordPage.subtitle",{defaultValue:"Enter your email to receive a reset link."})),v&&e.createElement(_,{message:v}),u?e.createElement("div",{className:"mt-6 rounded-lg border border-green-300 bg-green-50 p-4 text-green-800 text-sm"},t("ForgotPasswordPage.sent",{defaultValue:"If the email exists, we’ve sent a reset link. Please check your inbox."})):e.createElement("form",{className:"space-y-6 mt-4",onSubmit:g},e.createElement(P,{label:t("form.emailLabel"),type:"email",placeholder:t("form.emailPlaceholder"),color:i,value:w,onChange:p}),e.createElement("button",{type:"submit",disabled:c||!w,className:`relative flex w-full items-center justify-center gap-2 py-3 rounded-lg font-medium transition-colors ${c?"opacity-60 cursor-not-allowed":""} ${o} text-white`},c&&e.createElement("svg",{className:"h-4 w-4 animate-spin stroke-current",viewBox:"0 0 24 24",fill:"none"},e.createElement("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",strokeWidth:"4"}),e.createElement("path",{className:"opacity-75",d:"M4 12a8 8 0 018-8",strokeWidth:"4",strokeLinecap:"round"})),t("ForgotPasswordPage.sendLink",{defaultValue:"Send Reset Link"}))))))},ve=()=>{const t=F.useT("authLib"),l=h.useNavigate(),r=h.useLocation(),{colors:s,brandName:n=t("brandName",{defaultValue:"MyBrand"}),logoUrl:a}=X(),{api:o}=L(),{bgClass:m,textClass:i,borderClass:d}=J(s),w=`${m} bg-gradient-to-r from-white/10 via-white/0 to-white/0`,p=e.useMemo(()=>new URLSearchParams(r.search).get("token"),[r.search]),[c,S]=e.useState(""),[v,b]=e.useState(""),[u,k]=e.useState(!1),[g,y]=e.useState(null),x=6,j=p&&c.length>=x&&c===v;async function M(z){var D;if(z.preventDefault(),!u){if(y(null),!p){y(t("ResetPasswordPage.invalidLink",{defaultValue:"Invalid reset link."}));return}if(c.length<x){y(t("ResetPasswordPage.tooShort",{defaultValue:`Password must be at least ${x} characters.`}));return}if(c!==v){y(t("ResetPasswordPage.mismatch",{defaultValue:"Passwords do not match."}));return}k(!0);try{await o.post("/api/auth/reset-password",{token:p,newPassword:c}),l("/login",{replace:!0})}catch(C){const V=(D=C==null?void 0:C.response)==null?void 0:D.status;y(V===400||V===401||V===410?t("ResetPasswordPage.invalidOrExpired",{defaultValue:"Reset link is invalid or has expired. Request a new one."}):t("errors.generic",{defaultValue:"Something went wrong. Please try again."}))}finally{k(!1)}}}return e.createElement("div",{className:`flex items-center justify-center min-h-screen p-4 ${w}`},e.createElement("div",{className:"flex w-full max-w-xl bg-white rounded-2xl shadow-2xl overflow-hidden"},e.createElement("div",{className:"w-full p-6 md:p-8"},e.createElement("div",{className:"flex items-center justify-between mb-6"},a?e.createElement("img",{loading:"lazy",src:a,alt:"Brand Logo",className:`h-10 rounded-lg border ${d}`}):e.createElement("h2",{className:"text-xl font-bold"},n),e.createElement("button",{type:"button",onClick:()=>l("/login"),className:`text-sm ${i}`},t("ResetPasswordPage.backToLogin",{defaultValue:"Back to Sign In"}))),e.createElement("h1",{className:"text-2xl md:text-3xl font-bold text-gray-800"},t("ResetPasswordPage.title",{defaultValue:"Reset your password"})),e.createElement("p",{className:"mt-2 text-sm text-gray-600"},t("ResetPasswordPage.subtitle",{defaultValue:"Choose a new password to access your account."})),g&&e.createElement(_,{message:g}),!p&&e.createElement("div",{className:"mt-6 rounded-lg border border-red-300 bg-red-50 p-4 text-red-800 text-sm"},t("ResetPasswordPage.invalidLink",{defaultValue:"Invalid reset link."})),e.createElement("form",{className:"space-y-6 mt-4",onSubmit:M},e.createElement(P,{label:t("form.passwordLabel"),type:"password",placeholder:t("form.passwordPlaceholder"),color:d,value:c,onChange:S}),e.createElement(P,{label:t("ResetPasswordPage.confirmLabel",{defaultValue:"Confirm Password"}),type:"password",placeholder:t("ResetPasswordPage.confirmPlaceholder",{defaultValue:"Re-enter your password"}),color:d,value:v,onChange:b}),e.createElement("button",{type:"submit",disabled:u||!j,className:`relative flex w-full items-center justify-center gap-2 py-3 rounded-lg font-medium transition-colors ${u?"opacity-60 cursor-not-allowed":""} ${m} text-white`},u&&e.createElement("svg",{className:"h-4 w-4 animate-spin stroke-current",viewBox:"0 0 24 24",fill:"none"},e.createElement("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",strokeWidth:"4"}),e.createElement("path",{className:"opacity-75",d:"M4 12a8 8 0 018-8",strokeWidth:"4",strokeLinecap:"round"})),t("ResetPasswordPage.submit",{defaultValue:"Reset Password"}))))))},ke=({children:t})=>{const{isAuthenticated:l}=L(),r=h.useLocation();return l?t:e.createElement(h.Navigate,{to:"/login",state:{from:r},replace:!0})},Se=({config:t,children:l})=>{const r=h.useNavigate(),[s,n]=e.useState(()=>localStorage.getItem("authToken")),[a,o]=e.useState(null),[m,i]=e.useState(!0),[d,w]=e.useState(!1);async function p(){try{await c.post("/auth/logout")}catch(b){console.warn("Logout endpoint failed, proceeding with local logout:",b)}n(null),o(null),localStorage.removeItem("authToken"),sessionStorage.clear(),w(!1),r("/login",{replace:!0})}const c=e.useMemo(()=>{const b=ee.create({baseURL:t.baseUrl,withCredentials:!0});return be(b,{baseUrl:t.baseUrl,getAccessToken:()=>s,setAccessToken:u=>n(u),logout:()=>w(!0)}),b},[t.baseUrl,s]);e.useEffect(()=>{(async()=>{if(s){o(te(s)),i(!1);return}try{const{data:u}=await ee.post(`${t.baseUrl}/auth/refresh-token`,{},{withCredentials:!0});n(u.accessToken),o(te(u.accessToken)),localStorage.setItem("authToken",u.accessToken)}catch{}finally{i(!1)}})()},[s,t.baseUrl]);async function S(b){const{data:u}=await c.post("/api/auth/login",b);n(u.accessToken),o(te(u.accessToken)),localStorage.setItem("authToken",u.accessToken),xe(),r("/",{replace:!0})}const v=e.useMemo(()=>({isAuthenticated:!!s,accessToken:s,user:a,login:S,logout:p,api:c,setUser:o}),[s,a,c]);return e.createElement(ie.Provider,{value:t},e.createElement(ce.Provider,{value:v},e.createElement(h.Routes,null,e.createElement(h.Route,{path:"login",element:s?e.createElement(h.Navigate,{to:"/",replace:!0}):e.createElement(Ee,{baseUrl:t.baseUrl,colors:t.colors})}),e.createElement(h.Route,{path:"signup",element:s?e.createElement(h.Navigate,{to:"/",replace:!0}):e.createElement(ye,null)}),e.createElement(h.Route,{path:"forgot-password",element:e.createElement(Ne,null)}),e.createElement(h.Route,{path:"reset-password",element:e.createElement(ve,null)}),e.createElement(h.Route,{path:"oauth/google/callback",element:e.createElement(ge,null)}),e.createElement(h.Route,{path:"/oauth/microsoft/callback",element:e.createElement(ge,null)}),e.createElement(h.Route,{path:"*",element:e.createElement(ke,null,l)})),d&&e.createElement(we,{onConfirm:p})))};function se(...t){const{user:l}=L(),r=(l==null?void 0:l.roles)??[];return t.some(s=>r.includes(s))}function Me(t){const{user:l}=L();return(l==null?void 0:l.modules.includes(t))??!1}function K(...t){const{user:l}=L(),r=(l==null?void 0:l.permissions)??[];return t.every(s=>r.includes(s))}const Ie=({children:t,fallbackpermessions:l=[],anyPermessions:r=[],fallbackRoles:s=["super-admin"],redirectTo:n="/dashboard"})=>{if(s.some(i=>se(i)))return e.createElement(e.Fragment,null,t);const o=l.length===0||l.every(i=>K(i)),m=r.length===0||r.some(i=>K(i));return o&&m?e.createElement(e.Fragment,null,t):e.createElement(h.Navigate,{to:n,replace:!0})},re=e.createContext({}),Le=re.Provider;function Pe(t,l){var n,a,o;const s=(n=e.useContext(re)[t])==null?void 0:n[l];return s?!!((a=s.perms)!=null&&a.some(m=>K(m))||(o=s.fallbackRoles)!=null&&o.some(m=>se(m))):!1}const Ce=()=>{const{user:t,api:l,setUser:r}=L(),[s,n]=e.useState((t==null?void 0:t.name)??""),[a,o]=e.useState((t==null?void 0:t.email)??""),[m,i]=e.useState(!1),[d,w]=e.useState(!1),[p,c]=e.useState({open:!1,type:"success",title:"",message:""}),S="+971 50 827 8229";e.useEffect(()=>{if(!p.open)return;const g=window.setTimeout(()=>c(y=>({...y,open:!1})),3e3);return()=>window.clearTimeout(g)},[p.open]),e.useEffect(()=>{let g=!1;async function y(){try{const{data:x}=await l.get("/auth/client/me");if(g)return;r(x),n((x==null?void 0:x.name)??""),o((x==null?void 0:x.email)??"")}catch(x){console.error("Failed to load profile details:",x)}}return y(),()=>{g=!0}},[l,r]);const v=e.useMemo(()=>(s||(t==null?void 0:t.name)||(t==null?void 0:t.email)||"").trim(),[s,t==null?void 0:t.name,t==null?void 0:t.email]),b=e.useMemo(()=>v.charAt(0).toUpperCase()||"?",[v]);async function u(){if(t){w(!0);try{await l.patch("/auth/client/me",{name:s}),r({...t,name:s}),i(!1),c({open:!0,type:"success",title:"Changes saved",message:"Your profile was updated successfully."})}catch(g){console.error("Failed to update profile:",g),c({open:!0,type:"error",title:"Save failed",message:"Failed to save changes. Please try again."})}finally{w(!1)}}}if(!t)return e.createElement("p",{className:"text-sm text-gray-500"},"No user data available.");const k=p.type==="success";return e.createElement("div",{className:"max-w-3xl mx-auto"},p.open&&e.createElement("div",{className:"fixed top-6 right-6 z-[999999] flex items-center gap-3 rounded-xl border bg-white px-4 py-3 shadow-lg",role:"status","aria-live":"polite",style:{borderColor:k?"#BBF7D0":"#FECACA"}},e.createElement("div",{className:"flex h-9 w-9 items-center justify-center rounded-full",style:{backgroundColor:k?"#ECFDF5":"#FEF2F2"}},k?e.createElement("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"text-green-600"},e.createElement("path",{d:"M20 6L9 17L4 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})):e.createElement("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"text-red-600"},e.createElement("path",{d:"M12 9V13",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),e.createElement("path",{d:"M12 17H12.01",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),e.createElement("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0Z",stroke:"currentColor",strokeWidth:"2",strokeLinejoin:"round"}))),e.createElement("div",{className:"flex flex-col"},e.createElement("span",{className:"text-sm font-semibold",style:{color:k?"#15803D":"#B91C1C"}},p.title),p.message&&e.createElement("span",{className:"text-xs text-gray-500"},p.message)),e.createElement("button",{type:"button",onClick:()=>c(g=>({...g,open:!1})),className:"ml-2 rounded-md px-2 py-1 text-gray-500 hover:bg-gray-100","aria-label":"Close",title:"Close"},e.createElement("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("path",{d:"M18 6L6 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),e.createElement("path",{d:"M6 6L18 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})))),e.createElement("div",{className:"rounded-2xl border border-gray-200 bg-white shadow-sm"},e.createElement("div",{className:"px-6 pt-6 pb-4"},e.createElement("div",{className:"flex items-center justify-between"},e.createElement("div",{className:"flex items-center gap-4"},e.createElement("div",{className:"relative"},e.createElement("div",{className:"h-16 w-16 rounded-full bg-blue-600 flex items-center justify-center text-white text-2xl font-semibold"},b),e.createElement("button",{type:"button",className:"absolute -bottom-1 -right-1 h-8 w-8 rounded-full border border-gray-200 bg-white shadow-sm flex items-center justify-center hover:bg-gray-50",title:"Change avatar"},e.createElement("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("path",{d:"M12 20H21",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),e.createElement("path",{d:"M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5Z",stroke:"currentColor",strokeWidth:"2",strokeLinejoin:"round"})))),e.createElement("div",null,e.createElement("h1",{className:"text-2xl font-semibold"},"My Profile"),e.createElement("p",{className:"text-sm text-gray-500"},"Personal details"))),m?e.createElement("button",{type:"button",onClick:u,disabled:d,className:"rounded-full border border-blue-200 bg-blue-50 px-4 py-2 text-sm font-medium text-blue-700 hover:bg-blue-100 disabled:opacity-60"},d?"Saving…":"Save changes"):e.createElement("button",{type:"button",onClick:()=>i(!0),title:"Edit profile",className:"h-9 w-9 rounded-full border border-gray-200 bg-white shadow-sm flex items-center justify-center hover:bg-gray-50"},e.createElement("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("path",{d:"M12 20H21",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),e.createElement("path",{d:"M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5Z",stroke:"currentColor",strokeWidth:"2",strokeLinejoin:"round"}))))),e.createElement("div",{className:"px-6 pb-6 border-t border-gray-100 pt-6"},e.createElement("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5"},e.createElement("div",null,e.createElement("label",{className:"block text-xs font-medium text-gray-500 mb-2"},"Username"),e.createElement("input",{type:"text",value:s,disabled:!m||d,onChange:g=>n(g.target.value),className:`w-full rounded-lg border px-3 py-2 text-sm outline-none ${m?"border-gray-300 bg-white focus:border-blue-500 focus:ring-2 focus:ring-blue-100":"border-gray-200 bg-gray-50 text-gray-700"}`})),e.createElement("div",null,e.createElement("label",{className:"block text-xs font-medium text-gray-500 mb-2"},"Email ID"),e.createElement("input",{type:"email",value:a,disabled:!0,className:"w-full rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-sm text-gray-700 cursor-not-allowed"})),e.createElement("div",null,e.createElement("label",{className:"block text-xs font-medium text-gray-500 mb-2"},"Mobile number"),e.createElement("input",{type:"text",value:S,disabled:!0,className:"w-full rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-sm text-gray-700 cursor-not-allowed"}))),m&&e.createElement("button",{type:"button",disabled:d,onClick:()=>{i(!1),n((t==null?void 0:t.name)??"")},className:"mt-6 text-sm font-medium text-gray-600 hover:text-gray-900"},"Cancel"))))};f.AuthProvider=Se,f.ProfilePage=Ce,f.RbacContext=re,f.RbacProvider=Le,f.RequirePermissions=Ie,f.useAuthState=L,f.useCan=K,f.useGrant=Pe,f.useHasModule=Me,f.useHasRole=se,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ForgotPasswordPage.d.ts","sourceRoot":"","sources":["../../../src/pages/auth/ForgotPasswordPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AASxC,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAkGtC,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import React, { useState } from "react";
|
|
11
|
+
import { useT } from "@ciscode/ui-translate-core";
|
|
12
|
+
import { useNavigate } from "react-router-dom";
|
|
13
|
+
import { InputField } from "../../components/actions/InputField";
|
|
14
|
+
import { InlineError } from "../../components/InlineError";
|
|
15
|
+
import { useAuthConfig } from "../../context/AuthConfigContext";
|
|
16
|
+
import { useAuthState } from "../../context/AuthStateContext";
|
|
17
|
+
import { toTailwindColorClasses } from "../../utils/colorHelpers";
|
|
18
|
+
export const ForgotPasswordPage = () => {
|
|
19
|
+
const t = useT("authLib");
|
|
20
|
+
const navigate = useNavigate();
|
|
21
|
+
const { colors, brandName = t("brandName", { defaultValue: "MyBrand" }), logoUrl } = useAuthConfig();
|
|
22
|
+
const { api } = useAuthState();
|
|
23
|
+
const { bgClass, textClass, borderClass } = toTailwindColorClasses(colors);
|
|
24
|
+
const gradientClass = `${bgClass} bg-gradient-to-r from-white/10 via-white/0 to-white/0`;
|
|
25
|
+
const [email, setEmail] = useState("");
|
|
26
|
+
const [pending, setPending] = useState(false);
|
|
27
|
+
const [error, setError] = useState(null);
|
|
28
|
+
const [sent, setSent] = useState(false);
|
|
29
|
+
function handleSubmit(e) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
e.preventDefault();
|
|
32
|
+
if (pending)
|
|
33
|
+
return;
|
|
34
|
+
setError(null);
|
|
35
|
+
setPending(true);
|
|
36
|
+
try {
|
|
37
|
+
yield api.post("/api/auth/forgot-password", { email });
|
|
38
|
+
// Always show generic success regardless of user existence
|
|
39
|
+
setSent(true);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
// Do not enumerate users; still show success message
|
|
43
|
+
setSent(true);
|
|
44
|
+
console.error("Forgot password request failed", err);
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
setPending(false);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return (React.createElement("div", { className: `flex items-center justify-center min-h-screen p-4 ${gradientClass}` },
|
|
52
|
+
React.createElement("div", { className: "flex w-full max-w-xl bg-white rounded-2xl shadow-2xl overflow-hidden" },
|
|
53
|
+
React.createElement("div", { className: "w-full p-6 md:p-8" },
|
|
54
|
+
React.createElement("div", { className: "flex items-center justify-between mb-6" },
|
|
55
|
+
logoUrl ? (React.createElement("img", { loading: "lazy", src: logoUrl, alt: "Brand Logo", className: `h-10 rounded-lg border ${borderClass}` })) : (React.createElement("h2", { className: "text-xl font-bold" }, brandName)),
|
|
56
|
+
React.createElement("button", { type: "button", onClick: () => navigate("/login"), className: `text-sm ${textClass}` }, t("ForgotPasswordPage.backToLogin", { defaultValue: "Back to Sign In" }))),
|
|
57
|
+
React.createElement("h1", { className: "text-2xl md:text-3xl font-bold text-gray-800" }, t("ForgotPasswordPage.title", { defaultValue: "Forgot your password?" })),
|
|
58
|
+
React.createElement("p", { className: "mt-2 text-sm text-gray-600" }, t("ForgotPasswordPage.subtitle", { defaultValue: "Enter your email to receive a reset link." })),
|
|
59
|
+
error && React.createElement(InlineError, { message: error }),
|
|
60
|
+
sent ? (React.createElement("div", { className: "mt-6 rounded-lg border border-green-300 bg-green-50 p-4 text-green-800 text-sm" }, t("ForgotPasswordPage.sent", {
|
|
61
|
+
defaultValue: "If the email exists, we’ve sent a reset link. Please check your inbox."
|
|
62
|
+
}))) : (React.createElement("form", { className: "space-y-6 mt-4", onSubmit: handleSubmit },
|
|
63
|
+
React.createElement(InputField, { label: t("form.emailLabel"), type: "email", placeholder: t("form.emailPlaceholder"), color: borderClass, value: email, onChange: setEmail }),
|
|
64
|
+
React.createElement("button", { type: "submit", disabled: pending || !email, className: `relative flex w-full items-center justify-center gap-2 py-3 rounded-lg font-medium transition-colors ${pending ? "opacity-60 cursor-not-allowed" : ""} ${bgClass} text-white` },
|
|
65
|
+
pending && (React.createElement("svg", { className: "h-4 w-4 animate-spin stroke-current", viewBox: "0 0 24 24", fill: "none" },
|
|
66
|
+
React.createElement("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", strokeWidth: "4" }),
|
|
67
|
+
React.createElement("path", { className: "opacity-75", d: "M4 12a8 8 0 018-8", strokeWidth: "4", strokeLinecap: "round" }))),
|
|
68
|
+
t("ForgotPasswordPage.sendLink", { defaultValue: "Send Reset Link" }))))))));
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=ForgotPasswordPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ForgotPasswordPage.js","sourceRoot":"","sources":["../../../src/pages/auth/ForgotPasswordPage.tsx"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,CAAC,MAAM,kBAAkB,GAAa,GAAG,EAAE;IAC/C,MAAM,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;IAC1B,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,aAAa,EAAE,CAAC;IACrG,MAAM,EAAE,GAAG,EAAE,GAAG,YAAY,EAAE,CAAC;IAE/B,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAC3E,MAAM,aAAa,GAAG,GA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AC,qCAAqC,EAAC,OAAO,EAAC,WAAW,EAAC,IAAI,EAAC,MAAM;4BAClF,gCAAQ,SAAS,EAAC,YAAY,EAAC,EAAE,EAAC,IAAI,EAAC,EAAE,EAAC,IAAI,EAAC,CAAC,EAAC,IAAI,EAAC,WAAW,EAAC,GAAG,GAAG;4BACxE,8BAAM,SAAS,EAAC,YAAY,EAAC,CAAC,EAAC,mBAAmB,EAAC,WAAW,EAAC,GAAG,EAAC,aAAa,EAAC,OAAO,GAAG,CACvF,CACP;wBACA,CAAC,CAAC,6BAA6B,EAAE,EAAE,YAAY,EAAE,iBAAiB,EAAE,CAAC,CAC/D,CACJ,CACR,CACG,CACF,CACF,CACP,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResetPasswordPage.d.ts","sourceRoot":"","sources":["../../../src/pages/auth/ResetPasswordPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AASjD,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAsIrC,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import React, { useMemo, useState } from "react";
|
|
11
|
+
import { useT } from "@ciscode/ui-translate-core";
|
|
12
|
+
import { useLocation, useNavigate } from "react-router-dom";
|
|
13
|
+
import { InputField } from "../../components/actions/InputField";
|
|
14
|
+
import { InlineError } from "../../components/InlineError";
|
|
15
|
+
import { useAuthConfig } from "../../context/AuthConfigContext";
|
|
16
|
+
import { useAuthState } from "../../context/AuthStateContext";
|
|
17
|
+
import { toTailwindColorClasses } from "../../utils/colorHelpers";
|
|
18
|
+
export const ResetPasswordPage = () => {
|
|
19
|
+
const t = useT("authLib");
|
|
20
|
+
const navigate = useNavigate();
|
|
21
|
+
const location = useLocation();
|
|
22
|
+
const { colors, brandName = t("brandName", { defaultValue: "MyBrand" }), logoUrl } = useAuthConfig();
|
|
23
|
+
const { api } = useAuthState();
|
|
24
|
+
const { bgClass, textClass, borderClass } = toTailwindColorClasses(colors);
|
|
25
|
+
const gradientClass = `${bgClass} bg-gradient-to-r from-white/10 via-white/0 to-white/0`;
|
|
26
|
+
const token = useMemo(() => new URLSearchParams(location.search).get("token"), [location.search]);
|
|
27
|
+
const [newPassword, setNewPassword] = useState("");
|
|
28
|
+
const [confirmPassword, setConfirmPassword] = useState("");
|
|
29
|
+
const [pending, setPending] = useState(false);
|
|
30
|
+
const [error, setError] = useState(null);
|
|
31
|
+
const minLength = 6;
|
|
32
|
+
const valid = token && newPassword.length >= minLength && newPassword === confirmPassword;
|
|
33
|
+
function handleSubmit(e) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
var _a;
|
|
36
|
+
e.preventDefault();
|
|
37
|
+
if (pending)
|
|
38
|
+
return;
|
|
39
|
+
setError(null);
|
|
40
|
+
if (!token) {
|
|
41
|
+
setError(t("ResetPasswordPage.invalidLink", { defaultValue: "Invalid reset link." }));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (newPassword.length < minLength) {
|
|
45
|
+
setError(t("ResetPasswordPage.tooShort", { defaultValue: `Password must be at least ${minLength} characters.` }));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (newPassword !== confirmPassword) {
|
|
49
|
+
setError(t("ResetPasswordPage.mismatch", { defaultValue: "Passwords do not match." }));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
setPending(true);
|
|
53
|
+
try {
|
|
54
|
+
yield api.post("/api/auth/reset-password", { token, newPassword });
|
|
55
|
+
// On success, show brief confirmation then navigate to login
|
|
56
|
+
navigate("/login", { replace: true });
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
const status = (_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.status;
|
|
60
|
+
if (status === 400 || status === 401 || status === 410) {
|
|
61
|
+
setError(t("ResetPasswordPage.invalidOrExpired", {
|
|
62
|
+
defaultValue: "Reset link is invalid or has expired. Request a new one.",
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
setError(t("errors.generic", { defaultValue: "Something went wrong. Please try again." }));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
setPending(false);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return (React.createElement("div", { className: `flex items-center justify-center min-h-screen p-4 ${gradientClass}` },
|
|
75
|
+
React.createElement("div", { className: "flex w-full max-w-xl bg-white rounded-2xl shadow-2xl overflow-hidden" },
|
|
76
|
+
React.createElement("div", { className: "w-full p-6 md:p-8" },
|
|
77
|
+
React.createElement("div", { className: "flex items-center justify-between mb-6" },
|
|
78
|
+
logoUrl ? (React.createElement("img", { loading: "lazy", src: logoUrl, alt: "Brand Logo", className: `h-10 rounded-lg border ${borderClass}` })) : (React.createElement("h2", { className: "text-xl font-bold" }, brandName)),
|
|
79
|
+
React.createElement("button", { type: "button", onClick: () => navigate("/login"), className: `text-sm ${textClass}` }, t("ResetPasswordPage.backToLogin", { defaultValue: "Back to Sign In" }))),
|
|
80
|
+
React.createElement("h1", { className: "text-2xl md:text-3xl font-bold text-gray-800" }, t("ResetPasswordPage.title", { defaultValue: "Reset your password" })),
|
|
81
|
+
React.createElement("p", { className: "mt-2 text-sm text-gray-600" }, t("ResetPasswordPage.subtitle", { defaultValue: "Choose a new password to access your account." })),
|
|
82
|
+
error && React.createElement(InlineError, { message: error }),
|
|
83
|
+
!token && (React.createElement("div", { className: "mt-6 rounded-lg border border-red-300 bg-red-50 p-4 text-red-800 text-sm" }, t("ResetPasswordPage.invalidLink", { defaultValue: "Invalid reset link." }))),
|
|
84
|
+
React.createElement("form", { className: "space-y-6 mt-4", onSubmit: handleSubmit },
|
|
85
|
+
React.createElement(InputField, { label: t("form.passwordLabel"), type: "password", placeholder: t("form.passwordPlaceholder"), color: borderClass, value: newPassword, onChange: setNewPassword }),
|
|
86
|
+
React.createElement(InputField, { label: t("ResetPasswordPage.confirmLabel", { defaultValue: "Confirm Password" }), type: "password", placeholder: t("ResetPasswordPage.confirmPlaceholder", { defaultValue: "Re-enter your password" }), color: borderClass, value: confirmPassword, onChange: setConfirmPassword }),
|
|
87
|
+
React.createElement("button", { type: "submit", disabled: pending || !valid, className: `relative flex w-full items-center justify-center gap-2 py-3 rounded-lg font-medium transition-colors ${pending ? "opacity-60 cursor-not-allowed" : ""} ${bgClass} text-white` },
|
|
88
|
+
pending && (React.createElement("svg", { className: "h-4 w-4 animate-spin stroke-current", viewBox: "0 0 24 24", fill: "none" },
|
|
89
|
+
React.createElement("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", strokeWidth: "4" }),
|
|
90
|
+
React.createElement("path", { className: "opacity-75", d: "M4 12a8 8 0 018-8", strokeWidth: "4", strokeLinecap: "round" }))),
|
|
91
|
+
t("ResetPasswordPage.submit", { defaultValue: "Reset Password" })))))));
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=ResetPasswordPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResetPasswordPage.js","sourceRoot":"","sources":["../../../src/pages/auth/ResetPasswordPage.tsx"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,Q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C,IAAI,EAAC,EAAE,EAAC,IAAI,EAAC,CAAC,EAAC,IAAI,EAAC,WAAW,EAAC,GAAG,GAAG;4BACxE,8BAAM,SAAS,EAAC,YAAY,EAAC,CAAC,EAAC,mBAAmB,EAAC,WAAW,EAAC,GAAG,EAAC,aAAa,EAAC,OAAO,GAAG,CACvF,CACP;wBACA,CAAC,CAAC,0BAA0B,EAAE,EAAE,YAAY,EAAE,gBAAgB,EAAE,CAAC,CAC3D,CACJ,CACH,CACF,CACF,CACP,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignInPage.d.ts","sourceRoot":"","sources":["../../../src/pages/auth/SignInPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AASxC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"SignInPage.d.ts","sourceRoot":"","sources":["../../../src/pages/auth/SignInPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AASxC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAK1D,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAsQhD,CAAC"}
|
|
@@ -17,7 +17,8 @@ import { useAuthConfig } from "../../context/AuthConfigContext";
|
|
|
17
17
|
import { useAuthState } from "../../context/AuthStateContext";
|
|
18
18
|
import { InlineError } from "../../components/InlineError";
|
|
19
19
|
import { useT } from "@ciscode/ui-translate-core";
|
|
20
|
-
import { useNavigate, useLocation } from "react-router";
|
|
20
|
+
import { useNavigate, useLocation } from "react-router-dom";
|
|
21
|
+
import { Link } from "react-router-dom";
|
|
21
22
|
export const SignInPage = () => {
|
|
22
23
|
const t = useT("authLib");
|
|
23
24
|
const navigate = useNavigate();
|
|
@@ -137,7 +138,7 @@ export const SignInPage = () => {
|
|
|
137
138
|
React.createElement(InputField, { label: t("form.emailLabel"), type: "email", placeholder: t("form.emailPlaceholder"), color: borderClass, value: email, onChange: setEmail }),
|
|
138
139
|
React.createElement(InputField, { label: t("form.passwordLabel"), type: "password", placeholder: t("form.passwordPlaceholder"), color: borderClass, value: password, onChange: setPassword }),
|
|
139
140
|
React.createElement("div", { className: "ltr:text-right rtl:text-left" },
|
|
140
|
-
React.createElement(
|
|
141
|
+
React.createElement(Link, { to: "/forgot-password", className: textClass }, t("SignInPage.forgotPassword"))),
|
|
141
142
|
React.createElement("button", { type: "submit", disabled: pending, className: `relative flex w-full items-center justify-center gap-2 py-3 rounded-lg font-medium transition-colors ${pending ? "opacity-60 cursor-not-allowed" : ""} ${bgClass} text-white` },
|
|
142
143
|
pending && spinner,
|
|
143
144
|
pending ? t("SignInPage.signInSubmitting") : t("SignInPage.signIn")),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignInPage.js","sourceRoot":"","sources":["../../../src/pages/auth/SignInPage.tsx"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AACrE,OAAO,UAAU,MAAM,gDAAgD,CAAC;AACxE,OAAO,aAAa,MAAM,8CAA8C,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3D,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"SignInPage.js","sourceRoot":"","sources":["../../../src/pages/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C,mBAAmB,CAAC,CAC7D;oBAER,eAAe,CAAC,MAAM,GAAG,CAAC,IAAI,CAC7B;wBACE,6BAAK,SAAS,EAAC,wBAAwB;4BACrC,6BAAK,SAAS,EAAE,kBAAkB,OAAO,EAAE,GAAI;4BAC/C,8BAAM,SAAS,EAAE,GAAG,SAAS,eAAe,IACzC,CAAC,CAAC,wBAAwB,CAAC,CACvB;4BACP,6BAAK,SAAS,EAAE,kBAAkB,OAAO,EAAE,GAAI,CAC3C;wBACN,6BAAK,SAAS,EAAC,iDAAiD,IAC7D,eAAe,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAC5B,gCACE,GAAG,EAAE,GAAG,CAAC,EAAE,EACX,IAAI,EAAC,QAAQ,EACb,OAAO,EAAE,GAAG,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,EAAE,CAAC,EAC1C,SAAS,EAAC,QAAQ;4BAElB,oBAAC,YAAY,IAAC,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,GAAI,CAC3C,CACV,CAAC,CACE,CACL,CACJ,CACI,CACH,CACF,CACF,CACP,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignUpPage.d.ts","sourceRoot":"","sources":["../../../src/pages/auth/SignUpPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAYxC,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"SignUpPage.d.ts","sourceRoot":"","sources":["../../../src/pages/auth/SignUpPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAYxC,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAmV9B,CAAC"}
|
|
@@ -17,7 +17,7 @@ import { useAuthConfig } from "../../context/AuthConfigContext";
|
|
|
17
17
|
import { useAuthState } from "../../context/AuthStateContext";
|
|
18
18
|
import { InlineError } from "../../components/InlineError";
|
|
19
19
|
import { useT } from "@ciscode/ui-translate-core";
|
|
20
|
-
import { useNavigate, useLocation } from "react-router";
|
|
20
|
+
import { useNavigate, useLocation } from "react-router-dom";
|
|
21
21
|
export const SignUpPage = () => {
|
|
22
22
|
const t = useT("authLib");
|
|
23
23
|
const navigate = useNavigate();
|
|
@@ -30,11 +30,14 @@ export const SignUpPage = () => {
|
|
|
30
30
|
}, baseUrl, // IMPORTANT: used for OAuth redirect (same as SignIn)
|
|
31
31
|
} = useAuthConfig();
|
|
32
32
|
const { login, api } = useAuthState();
|
|
33
|
-
const [
|
|
33
|
+
const [fname, setFname] = useState("");
|
|
34
|
+
const [lname, setLname] = useState("");
|
|
35
|
+
const [username, setUsername] = useState("");
|
|
34
36
|
const [email, setEmail] = useState("");
|
|
35
37
|
const [password, setPassword] = useState("");
|
|
36
38
|
const [pending, setPending] = useState(false);
|
|
37
39
|
const [error, setError] = useState(null);
|
|
40
|
+
const [agreed, setAgreed] = useState(false);
|
|
38
41
|
const allProvidersData = {
|
|
39
42
|
google: { icon: googleIcon, label: t("social.google") },
|
|
40
43
|
microsoft: { icon: microsoftIcon, label: t("social.microsoft") },
|
|
@@ -57,11 +60,12 @@ export const SignUpPage = () => {
|
|
|
57
60
|
setError(null);
|
|
58
61
|
setPending(true);
|
|
59
62
|
try {
|
|
60
|
-
// 1) Register the
|
|
61
|
-
yield api.post("/auth/
|
|
63
|
+
// 1) Register the user
|
|
64
|
+
yield api.post("/api/auth/register", {
|
|
65
|
+
fullname: { fname, lname },
|
|
66
|
+
username,
|
|
62
67
|
email,
|
|
63
68
|
password,
|
|
64
|
-
name: name || undefined,
|
|
65
69
|
});
|
|
66
70
|
// 2) Auto-login after successful registration
|
|
67
71
|
yield login({ email, password });
|
|
@@ -152,11 +156,18 @@ export const SignUpPage = () => {
|
|
|
152
156
|
React.createElement("button", { type: "button", onClick: () => navigate("/login"), className: textClass }, t("SignUpPage.signIn", { defaultValue: "Sign in" })))),
|
|
153
157
|
error && React.createElement(InlineError, { message: error }),
|
|
154
158
|
React.createElement("form", { className: "space-y-6", onSubmit: handleSubmit },
|
|
155
|
-
React.createElement(
|
|
156
|
-
|
|
157
|
-
}), color: borderClass, value:
|
|
159
|
+
React.createElement("div", { className: "flex gap-2" },
|
|
160
|
+
React.createElement(InputField, { label: t("form.fnameLabel", { defaultValue: "First Name" }), type: "text", placeholder: t("form.fnamePlaceholder", { defaultValue: "Enter your first name" }), color: borderClass, value: fname, onChange: setFname }),
|
|
161
|
+
React.createElement(InputField, { label: t("form.lnameLabel", { defaultValue: "Last Name" }), type: "text", placeholder: t("form.lnamePlaceholder", { defaultValue: "Enter your last name" }), color: borderClass, value: lname, onChange: setLname })),
|
|
162
|
+
React.createElement(InputField, { label: t("form.usernameLabel", { defaultValue: "Username" }), type: "text", placeholder: t("form.usernamePlaceholder", { defaultValue: "Choose a username" }), color: borderClass, value: username, onChange: setUsername }),
|
|
158
163
|
React.createElement(InputField, { label: t("form.emailLabel"), type: "email", placeholder: t("form.emailPlaceholder"), color: borderClass, value: email, onChange: setEmail }),
|
|
159
164
|
React.createElement(InputField, { label: t("form.passwordLabel"), type: "password", placeholder: t("form.passwordPlaceholder"), color: borderClass, value: password, onChange: setPassword }),
|
|
165
|
+
React.createElement("div", { className: "flex items-center gap-2" },
|
|
166
|
+
React.createElement("input", { id: "agree", type: "checkbox", checked: agreed, onChange: e => setAgreed(e.target.checked), className: "form-checkbox" }),
|
|
167
|
+
React.createElement("label", { htmlFor: "agree", className: "text-sm" },
|
|
168
|
+
"I agree to the ",
|
|
169
|
+
React.createElement("span", { className: "underline cursor-pointer" }, "terms and conditions"),
|
|
170
|
+
" (placeholder)")),
|
|
160
171
|
React.createElement("button", { type: "submit", disabled: pending, className: `relative flex w-full items-center justify-center gap-2 py-3 rounded-lg font-medium transition-colors ${pending ? "opacity-60 cursor-not-allowed" : ""} ${bgClass} text-white` },
|
|
161
172
|
pending && spinner,
|
|
162
173
|
pending
|