PageSourceSearch

https://skill-build.ai/assets/authService-D5_kcMgf.js

js skill-build.ai collected 2026-10-05 15:03:22 UTC 8,269 bytes, 1 lines download raw bytes

1import{ae as n,aj as i,E as d,A as l,aZ as f,a3 as w}from"./index-DICudJnO.js";import{U as u}from"./enums-BLQAdH2o.js";const h="oidcIdToken",E={async login(a){try{const r={email:a.email.trim().toLowerCase(),tenantCode:a.tenantCode};a.pin?r.pin=a.pin:r.password=a.password??"";const e=(await n.post("/auth/login",{...r})).data.data;if(!e)throw new Error("Invalid response from server");if(e.mfaRequired&&e.mfaToken)return{accessToken:"",refreshToken:"",userId:"",tenantId:"",tenantCode:a.tenantCode,user:null,mfaRequired:!0,mfaToken:e.mfaToken};const s={id:e.userId,tenantId:e.tenantId,email:e.email,fullName:e.fullName||`${e.firstName||""} ${e.lastName||""}`.trim(),firstName:e.firstName,lastName:e.lastName,role:e.role,status:u.ACTIVE,mustChangePassword:!!e.mustChangePassword,createdAt:new Date().toISOString()};return e.mfaSetupRequired?{accessToken:e.accessToken,refreshToken:e.refreshToken,userId:e.userId,tenantId:e.tenantId,tenantCode:e.tenantCode,user:s,mfaSetupRequired:!0}:{accessToken:e.accessToken,refreshToken:e.refreshToken,userId:e.userId,tenantId:e.tenantId,tenantCode:e.tenantCode,user:s}}catch(t){if(t instanceof i){if(!t.response)throw t.code==="ECONNREFUSED"||t.code==="ERR_NETWORK"?new Error("Unable to connect to server. Please check your internet connection and try again."):t.code==="ETIMEDOUT"||t.message.includes("timeout")?new Error("Request timed out. Please check your connection and try again."):new Error("Unable to connect to server. Please try again later.");const r=t.response.status,o=t.response.data;let e="";throw o&&(typeof o=="string"?e=o:typeof o=="object"&&(e=o.message||o.error||"")),r===401?new Error(e||"Invalid email or password. Please check your credentials and try again."):r===429?new Error(e||"Too many login attempts. Please wait a moment and try again."):r===400?
1new Error(e||"Invalid login request. Please check your organization and credentials, then try again."):r===403?new Error(e||"Access denied. Please contact your administrator."):r===404?new Error("Login service not found. Please contact support."):r>=500?new Error("Server error. Please try again later or contact support if the problem persists."):r>=400?new Error(e||"Login failed. Please check your information and try again."):new Error(e||"An unexpected error occurred. Please try again.")}throw t instanceof Error?t:new Error("An unexpected error occurred. Please try again.")}},async verifyTenant(a){try{const r=(await n.get("/auth/verify-tenant",{params:{tenantCode:a}})).data.data;if(!r)throw new Error("Invalid response from server");return{...r,verificationEnabled:!0}}catch(t){if(t instanceof i){if(!t.response)throw new Error("Unable to verify the tenant right now. Please try again.");const r=t.response.status,o=t.response.data,e=(o==null?void 0:o.message)||(o==null?void 0:o.error)||"";if(r===400)throw new Error(e||"Tenant code is required.");if(r===429)throw new Error(e||"Too many verification attempts. Please wait and try again.");if(r===404){if(e.toLowerCase().includes("not enabled"))return{valid:!0,verificationEnabled:!1};throw new Error(e||"We could not verify the tenant. Please try again.")}throw r>=500?new Error("Tenant verification service is unavailable. Please try again later."):new Error(e||"Unable to verify tenant. Please try again.")}throw t instanceof Error?t:new Error("Unable to verify tenant. Please try again.")}},async getVerifyTenantLockStatus(){var a;try{const r=(await n.get("/auth/verify-tenant/lock-status")).data.data;return r||{locked:!1}}catch(t){return t instanceof i&&((a=t.response)==null?void 0:a.status)===404?{locked:!1}:{locked:!1}}},async unlockVerifyTenantLock(a){const r=(await n.post("/auth/verify-tenant/unlock",null,{params:{ip:a}})).data.data;if(!r)throw new Error("Invalid response from server");return r},async oidcAuthorize(a){try{const t=(a==null?void 0:a.tenantCode)||l()||f()||d().code||void 0,o=(await n.get("/auth/oidc/authorize",{params:{...a,tenant_code:t}})).data.data;if(!o)throw new Error("Invalid response from server");return o}catch(t){if(t instanceof i){if(!t.response)throw new Error("Unable to connect to server. Please try again later.");const r=t.response.status,o=t.response.data,e=(o==null?void 0:o.message)||(o==null?void 0:o.error)||"";throw r===400?new Error(e||"Tenant code is required for passkey sign-in."):r===404?new Error(e||"Tenant not found. Please check your organization code."):r===409?new Error(e||"Sign in with a passkey is not enabled for this client."):r>=500?new Error("Server error. Please try again later."):new Error(e||"OIDC authorization failed.")}throw t instanceof Error?t:new Error("OIDC authorization failed.")}},async oidcCallback(a){const r=(await n.post("/auth/oidc/callback",a)).data.data;if(!r)throw new Error("Invalid response from server");return r},async oidcRefresh(a){const r=(await n.post("/auth/oidc/refresh",{refreshToken:a})).data.data;if(!r)throw new Error("Invalid response from server");return r},async oidcLogout(a){await n.post("/auth/oidc/logout",a)},async logout(){try{const a=localStorage.getItem("accessToken"),t=localStorage.getItem("refreshToken"),r=a?w(a):null;if(!!(r&&typeof r.iss=="string")&&t){const e=localStorage.getItem(h)||void 0;await n.post("/auth/oidc/logout",{refreshToken:t,idTokenHint:e,postLogoutRedirectUri:window.location.origin+"/login"})}else await n.post("/auth/logout")}catch(a){console.warn("Logout API call failed:",a)}},async refreshToken(a){const t=localStorage.getItem("accessToken"),r=t?w(t):null;if(!!(r&&typeof r.iss=="string")){const c=(await n.post("/auth/oidc/refresh",{refreshToken:a})).data.data;if(!c||!c.access_token)throw new Error("Invalid response from server");return{accessToken:c.access_token,refreshToken:c.refresh_token}}const s=(await n.post("/auth/refresh",{refreshToken:a})).data.data;if(!s)throw new Error("Invalid response from server");return{accessToken:s.accessToken,refreshToken:s.refreshToken}},async getCurrentUser(){const t=(await n.get("/auth/me")).data.data;if(!t)throw new Error("Invalid response from server");return t},async changePassword(a,t){try{await n.post("/auth/change-password",{currentPassword:a,newPassword:t})}catch(r){if(r instanceof i){if(!r.response)throw new Error("Unable to connect to server. Please check your connection and try again.");const o=r.response.status,e=r.response.data,s=typeof e=="object"&&e!==null?e.message||e.error:typeof e=="string"?e:"";throw o===401?new Error(s||"Current password is incorrect. Please try again."):o===400?new Error(s||"Invalid password. Please check the requirements and try again."):o>=500?new Error("Server error. Please try again later."):new Error(s||"Failed to change password. Please try again.")}throw r instanceof Error?r:new Error("An unexpected error occurred. Please try again.")}},async requestPasswordReset(a){try{const t=d(),r=l()||t.code||f();if(!r)throw new Error("Organization code is required.");await n.post("/auth/forgot-password",{email:a,tenantCode:r})}catch(t){if(t instanceof i){if(!t.response)throw new Error("Unable to connect to server. Please check your connection and try again.");const r=t.response.status,o=t.response.data,e=typeof o=="object"&&o!==null?o.message||o.error:typeof o=="str
1ing"?o:"";throw r===404?new Error(e||"Email address not found. Please check and try again."):r>=500?new Error("Server error. Please try again later."):new Error(e||"Failed to send password reset email. Please try again.")}throw t instanceof Error?t:new Error("An unexpected error occurred. Please try again.")}},async resetPassword(a,t){try{await n.post("/auth/reset-password",{token:a,newPassword:t})}catch(r){if(r instanceof i){if(!r.response)throw new Error("Unable to connect to server. Please check your connection and try again.");const o=r.response.status,e=r.response.data,s=typeof e=="object"&&e!==null?e.message||e.error:typeof e=="string"?e:"";throw o===400||o===401?new Error(s||"Invalid or expired reset token. Please request a new password reset."):o>=500?new Error("Server error. Please try again later."):new Error(s||"Failed to reset password. Please try again.")}throw r instanceof Error?r:new Error("An unexpected error occurred. Please try again.")}},async validateToken(){try{return await n.get("/auth/validate"),!0}catch{return!1}}};export{E as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.