@tempots/beatui 1.2.0 → 1.2.1
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/auth/index.cjs.js +1 -1
- package/dist/auth/index.es.js +1 -1
- package/dist/{auth-divider-DGNQZKEb.js → auth-divider-D_3gKZ6g.js} +469 -461
- package/dist/auth-divider-itm5-j5G.cjs +1 -0
- package/dist/better-auth/index.cjs.js +1 -1
- package/dist/better-auth/index.es.js +52 -48
- package/dist/types/better-auth/types.d.ts +5 -1
- package/dist/types/components/auth/auth-container.d.ts +1 -1
- package/package.json +1 -1
- package/dist/auth-divider-DfWGT38w.cjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("@tempots/dom"),q=require("./stack-dwLevGa2.cjs"),_=require("./use-form-BvBkVEKi.cjs"),f=require("./modal-DCxNGrzk.cjs"),X=require("@tempots/std"),m=require("./translations-C_-cObaF.cjs"),y=require("./notice-Q0A1gIho.cjs"),T=require("./input-container-BkPcNDaZ.cjs"),ae=require("./text-input-D_IxFd0M.cjs"),ne=require("./translations-qefRsdGi.cjs"),re=require("@tempots/ui"),$={google:{name:"Google",icon:"logos:google-icon",color:"#4285f4"},github:{name:"GitHub",icon:"logos:github-icon",color:"#333"},apple:{name:"Apple",icon:"logos:apple",color:"#000"},facebook:{name:"Facebook",icon:"logos:facebook",color:"#1877f2"},twitter:{name:"Twitter",icon:"logos:twitter",color:"#1da1f2"},microsoft:{name:"Microsoft",icon:"logos:microsoft-icon",color:"#00a4ef"},discord:{name:"Discord",icon:"logos:discord-icon",color:"#5865f2"},linkedin:{name:"LinkedIn",icon:"logos:linkedin-icon",color:"#0077b5"},instagram:{name:"Instagram",icon:"logos:instagram-icon",color:"#e4405f"},tiktok:{name:"TikTok",icon:"logos:tiktok-icon",color:"#000"},snapchat:{name:"Snapchat",icon:"logos:snapchat-icon",color:"#fffc00"},reddit:{name:"Reddit",icon:"logos:reddit-icon",color:"#ff4500"},pinterest:{name:"Pinterest",icon:"logos:pinterest-icon",color:"#bd081c"},twitch:{name:"Twitch",icon:"logos:twitch",color:"#9146ff"},steam:{name:"Steam",icon:"logos:steam-icon",color:"#000"},epic:{name:"Epic Games",icon:"simple-icons:epicgames",color:"#313131"},playstation:{name:"PlayStation",icon:"logos:playstation-icon",color:"#003791"},xbox:{name:"Xbox",icon:"logos:xbox-icon",color:"#107c10"},whatsapp:{name:"WhatsApp",icon:"logos:whatsapp-icon",color:"#25d366"},wechat:{name:"WeChat",icon:"logos:wechat-icon",color:"#1aad19"},amazon:{name:"Amazon",icon:"logos:amazon-icon",color:"#ff9900"},yahoo:{name:"Yahoo",icon:"logos:yahoo-icon",color:"#720e9e"},paypal:{name:"PayPal",icon:"logos:paypal",color:"#0070ba"},x:{name:"X",icon:"simple-icons:x",color:"#000"}};function Y(t){return $[t]?.name||t}function se(t){return $[t]?.icon||"mdi:account"}function ie(t){return $[t]?.color||"#666"}function ce(t,o="Continue with {provider}"){return o.replace("{provider}",Y(t))}const B={minLength:8,requireUppercase:!0,requireLowercase:!0,requireNumbers:!0,requireSymbols:!1};function le(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}function Z(t=32){const o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let r="";for(let a=0;a<t;a++)r+=o.charAt(Math.floor(Math.random()*o.length));return r}function ue(t,o,r,a=[],c={}){const s={google:"https://accounts.google.com/oauth/authorize",github:"https://github.com/login/oauth/authorize",apple:"https://appleid.apple.com/auth/authorize",facebook:"https://www.facebook.com/v18.0/dialog/oauth",twitter:"https://twitter.com/i/oauth2/authorize",microsoft:"https://login.microsoftonline.com/common/oauth2/v2.0/authorize",discord:"https://discord.com/api/oauth2/authorize",linkedin:"https://www.linkedin.com/oauth/v2/authorization",instagram:"https://api.instagram.com/oauth/authorize",tiktok:"https://www.tiktok.com/v2/auth/authorize",snapchat:"https://accounts.snapchat.com/accounts/oauth2/authorize",reddit:"https://www.reddit.com/api/v1/authorize",pinterest:"https://api.pinterest.com/oauth/",twitch:"https://id.twitch.tv/oauth2/authorize",steam:"https://steamcommunity.com/oauth/authorize",epic:"https://auth.epicgames.com/authorize",playstation:"https://auth.api.sonyentertainmentnetwork.com/oauth/authorize",xbox:"https://login.live.com/oauth20_authorize.srf",whatsapp:"https://web.whatsapp.com/oauth/authorize",wechat:"https://open.weixin.qq.com/connect/qrconnect",amazon:"https://www.amazon.com/ap/oa",yahoo:"https://api.login.yahoo.com/oauth2/request_auth",paypal:"https://www.paypal.com/signin/authorize",x:"https://api.twitter.com/oauth2/authorize"},u={google:["openid","email","profile"],github:["user:email"],apple:["email","name"],facebook:["email"],twitter:["users.read"],microsoft:["openid","email","profile"],discord:["identify","email"],linkedin:["r_liteprofile","r_emailaddress"],instagram:["user_profile","user_media"],tiktok:["user.info.basic","user.external.id"],snapchat:["user.info.basic","user.external.id"],reddit:["identity","email"],pinterest:["read_public","read_relationships"],twitch:["openid","email","profile"],steam:["openid","email","profile"],epic:["openid","email","profile"],playstation:["openid","email","profile"],xbox:["openid","email","profile"],whatsapp:["openid","email","profile"],wechat:["openid","email","profile"],amazon:["openid","email","profile"],yahoo:["openid","email","profile"],paypal:["openid","email","profile"],x:["openid","email","profile"]},n=s[t];if(!n)throw new Error(`Unsupported provider: ${t}`);const l=a.length>0?a:u[t],i=Z(),h=new URLSearchParams({client_id:o,redirect_uri:r,scope:l.join(" "),state:i,response_type:"code",...c});return`${n}?${h.toString()}`}function me(t,o,r,a){const c=window.open(t,`${o}_login`,"width=500,height=600,scrollbars=yes,resizable=yes");if(!c){a?.(new Error("Failed to open popup window"));return}const s=setInterval(()=>{c.closed&&(clearInterval(s),a?.(new Error("Login cancelled")))},1e3),u=n=>{n.origin===window.location.origin&&(n.data.type==="SOCIAL_LOGIN_SUCCESS"?(clearInterval(s),c.close(),window.removeEventListener("message",u),r?.(n.data.result)):n.data.type==="SOCIAL_LOGIN_ERROR"&&(clearInterval(s),c.close(),window.removeEventListener("message",u),a?.(new Error(n.data.error))))};window.addEventListener("message",u)}function de(t){return t instanceof Error?t.message:typeof t=="string"?t:t&&typeof t=="object"&&"message"in t?String(t.message):"An unexpected error occurred"}function pe(){return typeof window<"u"&&typeof document<"u"}function E({task:t,message:o,onStart:r,onEnd:a}){return async c=>{r?.();const s=await _.taskToValidation({task:t!=null?()=>t(c):async()=>null,errorMessage:o,errorPath:["root"],validation:u=>u!=null?X.Validation.invalid({message:u}):X.Validation.valid});return a?.(),s}}function M(t=B,o){const r=o??m.defaultMessages;let a=f.string();return t.minLength&&(a=a.min(t.minLength,(r.passwordMinLength??m.defaultMessages.passwordMinLength)(t.minLength))),t.requireUppercase&&(a=a.regex(/[A-Z]/,r.passwordRequireUppercase??m.defaultMessages.passwordRequireUppercase)),t.requireLowercase&&(a=a.regex(/[a-z]/,r.passwordRequireLowercase??m.defaultMessages.passwordRequireLowercase)),t.requireNumbers&&(a=a.regex(/[0-9]/,r.passwordRequireNumber??m.defaultMessages.passwordRequireNumber)),t.requireSymbols&&(a=a.regex(/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/,r.passwordRequireSpecialChar??m.defaultMessages.passwordRequireSpecialChar)),t.customValidation&&(a=a.refine(c=>t.customValidation(c))),a}function C(t){const o=t??m.defaultMessages;return f.string().min(1,o.emailRequired??m.defaultMessages.emailRequired).email(o.invalidEmail??m.defaultMessages.invalidEmail)}const G=C();function z(t,o){const r=o??m.defaultMessages,a=t?M(t,o):f.string().refine(c=>c.length>0?null:r.passwordRequired??m.defaultMessages.passwordRequired);return f.object({email:C(o),password:a,rememberMe:f.boolean().default(!1)}).schema()}function U(t=B,o,r){const a=r??m.defaultMessages,c=M(t,r),s=o?.showNameField!==!1,u=o?.showConfirmPassword!==!1,n=o?.showAcceptTermsAndConditions!==!1,l={name:s?f.string().min(1,a.nameRequired??m.defaultMessages.nameRequired).optional():f.string().optional(),email:C(r),password:c,confirmPassword:u?f.string().min(1,a.confirmPasswordRequired??m.defaultMessages.confirmPasswordRequired):f.string(),acceptTerms:n?f.boolean().refine(h=>h===!0,a.acceptTermsRequired??m.defaultMessages.acceptTermsRequired):f.boolean().default(!0)},i=f.object(l);return u?i.refine(h=>h.password===h.confirmPassword?null:a.passwordsDoNotMatch??m.defaultMessages.passwordsDoNotMatch,{path:["confirmPassword"]}).schema():i.schema()}const j=f.object({email:G}).schema(),he=z(),ge=U(),fe={signIn:z,signUp:U,resetPassword:()=>j};function be(t,o){const r=o??m.defaultMessages,c=(o?C(o):G).validate(t);return c.success?null:c.errors[0]?.message||(r.invalidEmailAddress??m.defaultMessages.invalidEmailAddress)}function we(t,o=B,r){const a=r??m.defaultMessages,s=M(o,r).validate(t);return s.success?null:s.errors[0]?.message||(a.invalidPassword??m.defaultMessages.invalidPassword)}function R(t,o=B){const r={length:t.length>=(o.minLength||8),uppercase:/[A-Z]/.test(t),lowercase:/[a-z]/.test(t),numbers:/[0-9]/.test(t),symbols:/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(t),custom:o.customValidation?o.customValidation(t)===null:t.length>0},a=[!0,o.requireUppercase,o.requireLowercase,o.requireNumbers,o.requireSymbols,!!o.customValidation].filter(Boolean).length,c=[r.length,o.requireUppercase?r.uppercase:null,o.requireLowercase?r.lowercase:null,o.requireNumbers?r.numbers:null,o.requireSymbols?r.symbols:null,o.customValidation?r.custom:null].filter(n=>n===!0).length,s=a>0?Math.round(c/a*100):0;let u;return s<40?u="weak":s<60?u="fair":s<80?u="good":u="strong",{strength:u,score:s,checks:r}}const H=()=>e.localStorageProp({key:"bui_auth_email",defaultValue:null});function J({onSignIn:t,passwordRules:o,labels:r,showRememberMe:a}){const c=e.prop(!1),s=H(),u=z(o),n=_.useForm({schema:u,onSubmit:E({task:t,message:"Sign in failed",onStart:()=>{c.set(!0),n.controller.disable()},onEnd:()=>{c.set(!1),n.controller.enable()}}),initialValue:{email:"",password:""}}),{controller:l,submit:i}=n;c.on(l.setDisabled);const h=l.field("email"),b=l.field("password");return s.on(w=>{w!=null&&h.change(w)}),h.signal.on(w=>{s.value!=null&&(s.value=w)}),e.Use(m.AuthI18n,w=>e.html.form(e.attr.class("bc-auth-form__form"),e.on.submit(i),q.Stack(e.attr.class("bc-auth-form__fields"),e.Ensure(l.error,v=>y.Notice({variant:"danger",tone:"prominent",role:"alert"},e.html.div(v))),_.Control(y.EmailInput,{controller:h,label:e.coalesce(r?.emailLabel,w.$.emailLabel)}),_.Control(y.PasswordInput,{controller:b,label:e.coalesce(r?.passwordLabel,w.$.passwordLabel)}),e.When(a??!0,()=>e.html.div(e.attr.class("bc-auth-form__remember-me"),e.html.label(e.attr.class("bc-auth-form__checkbox-label"),_.CheckboxInput({value:s.map(v=>v!=null),after:e.html.span(e.coalesce(r?.rememberMeLabel,w.$.rememberMeLabel)),onChange:v=>{v?s.value=h.signal.value??"":s.value=null}}))))),T.Button({type:"submit",variant:"filled",color:"primary",loading:c,disabled:l.disabledOrHasErrors},e.attr.class("bc-auth-form__submit"),e.coalesce(r?.signInButton,w.$.signInButton))))}function K({password:t,rules:o=B,showLabel:r=!0,className:a}){const c=e.computedOf(t)(i=>!i||i.length===0?{strength:"weak",score:0,checks:{length:!1,uppercase:!1,lowercase:!1,numbers:!1,symbols:!1,custom:!1}}:R(i,o)),s=c.map(i=>i.strength),u=c.map(i=>i.score),n=c.map(i=>i.checks),l=e.computedOf(s,a)((i,h)=>["bc-password-strength",`bc-password-strength--${i}`,h].filter(Boolean).join(" "));return e.html.div(e.attr.class(l),e.html.div(e.attr.class("bc-password-strength__bar"),e.html.div(e.attr.class("bc-password-strength__fill"),e.attr.style(u.map(i=>`width: ${i}%`)))),e.When(r,()=>e.Use(m.AuthI18n,i=>e.html.div(e.attr.class("bc-password-strength__label"),e.computedOf(s,i)((h,b)=>{switch(h){case"weak":return b.passwordStrengthWeak;case"fair":return b.passwordStrengthFair;case"good":return b.passwordStrengthGood;case"strong":return b.passwordStrengthStrong;default:return b.passwordStrengthWeak}})))),e.html.div(e.attr.class("bc-password-strength__requirements"),e.When(o.minLength!==void 0,()=>e.html.div(e.attr.class("bc-password-strength__requirement"),e.attr.class(e.computedOf(n)(i=>i.length?"bc-password-strength__requirement--met":"")),e.html.span(e.attr.class("bc-password-strength__requirement-icon"),e.computedOf(n)(i=>i.length?"✓":"○")),e.html.span(e.attr.class("bc-password-strength__requirement-text"),`At least ${o.minLength} characters`))),e.When(o.requireUppercase===!0,()=>e.html.div(e.attr.class("bc-password-strength__requirement"),e.attr.class(e.computedOf(n)(i=>i.uppercase?"bc-password-strength__requirement--met":"")),e.html.span(e.attr.class("bc-password-strength__requirement-icon"),e.computedOf(n)(i=>i.uppercase?"✓":"○")),e.html.span(e.attr.class("bc-password-strength__requirement-text"),"One uppercase letter"))),e.When(o.requireLowercase===!0,()=>e.html.div(e.attr.class("bc-password-strength__requirement"),e.attr.class(e.computedOf(n)(i=>i.lowercase?"bc-password-strength__requirement--met":"")),e.html.span(e.attr.class("bc-password-strength__requirement-icon"),e.computedOf(n)(i=>i.lowercase?"✓":"○")),e.html.span(e.attr.class("bc-password-strength__requirement-text"),"One lowercase letter"))),e.When(o.requireNumbers===!0,()=>e.html.div(e.attr.class("bc-password-strength__requirement"),e.attr.class(e.computedOf(n)(i=>i.numbers?"bc-password-strength__requirement--met":"")),e.html.span(e.attr.class("bc-password-strength__requirement-icon"),e.computedOf(n)(i=>i.numbers?"✓":"○")),e.html.span(e.attr.class("bc-password-strength__requirement-text"),"One number"))),e.When(o.requireSymbols===!0,()=>e.html.div(e.attr.class("bc-password-strength__requirement"),e.attr.class(e.computedOf(n)(i=>i.symbols?"bc-password-strength__requirement--met":"")),e.html.span(e.attr.class("bc-password-strength__requirement-icon"),e.computedOf(n)(i=>i.symbols?"✓":"○")),e.html.span(e.attr.class("bc-password-strength__requirement-text"),"One special character")))))}function Le({password:t,rules:o=B,className:r}){const a=e.computedOf(t)(n=>!n||n.length===0?{strength:"weak",score:0}:R(n,o)),c=a.map(n=>n.strength),s=a.map(n=>n.score),u=e.computedOf(c,r)((n,l)=>["bc-password-strength-bar",`bc-password-strength-bar--${n}`,l].filter(Boolean).join(" "));return e.html.div(e.attr.class(u),e.html.div(e.attr.class("bc-password-strength-bar__fill"),e.attr.style(s.map(n=>`width: ${n}%`))))}function _e({password:t,rules:o=B,className:r}){const a=e.computedOf(t)(s=>!s||s.length===0?"weak":R(s,o).strength),c=e.computedOf(a,r)((s,u)=>["bc-password-strength-text",`bc-password-strength-text--${s}`,u].filter(Boolean).join(" "));return e.Use(m.AuthI18n,s=>e.html.span(e.attr.class(c),e.computedOf(a,s)((u,n)=>{switch(u){case"weak":return n.passwordStrengthWeak;case"fair":return n.passwordStrengthFair;case"good":return n.passwordStrengthGood;case"strong":return n.passwordStrengthStrong;default:return n.passwordStrengthWeak}})))}function Q({passwordRules:t,labels:o,initialEmail:r,initialName:a,showPasswordStrength:c,onSignUp:s,showNameField:u,showConfirmPassword:n,showAcceptTermsAndConditions:l,termsAndConditions:i}){const h=e.prop(!1),b=t||B,w=typeof n=="boolean"?n:n!=null?n.value:!1,v=typeof l=="boolean"?l:l!=null?l.value:!1,O=U(b,{showNameField:u!==!1,showConfirmPassword:w,showAcceptTermsAndConditions:v}),x=_.useForm({schema:O,onSubmit:E({task:s!=null?L=>s({email:L.email,password:L.password,name:L.name,acceptTerms:L.acceptTerms}):void 0,message:"Sign up failed",onStart:()=>{h.set(!0),x.controller.disable()},onEnd:()=>{h.set(!1),x.controller.enable()}}),initialValue:{name:a??"",email:r??"",password:"",confirmPassword:"",acceptTerms:!1}}),{controller:k,submit:W}=x;h.on(k.setDisabled);const F=k.field("name"),V=k.field("email"),P=k.field("password"),S=k.field("confirmPassword"),I=k.field("acceptTerms");return e.Use(m.AuthI18n,L=>e.html.form(e.attr.class("bc-auth-form__form"),e.on.submit(W),q.Stack(e.attr.class("bc-auth-form__fields"),e.Ensure(k.error,g=>y.Notice({variant:"danger",tone:"prominent",role:"alert"},e.html.div(g))),e.When(u!==!1,()=>_.Control(ae.TextInput,{controller:F.transform(g=>g??"",g=>g===""?void 0:g),label:e.coalesce(o?.nameLabel,L.$.nameLabel)})),_.Control(y.EmailInput,{controller:V,label:e.coalesce(o?.emailLabel,L.$.emailLabel)}),_.Control(y.PasswordInput,{controller:P,label:e.coalesce(o?.passwordLabel,L.$.passwordLabel)}),e.When(c??!1,()=>K({password:P.signal,rules:b,showLabel:!0})),e.When(n??!1,()=>_.Control(y.PasswordInput,{controller:S,label:e.coalesce(o?.confirmPasswordLabel,L.$.confirmPasswordLabel)})),e.When(l??!1,()=>e.html.div(e.attr.class("bc-auth-form__terms"),e.html.label(e.attr.class("bc-auth-form__checkbox-label"),_.CheckboxInput({value:I.signal.map(g=>g??!1),onChange:g=>I.change(g)}),e.html.span(i||e.coalesce(o?.acceptTermsLabel,L.$.acceptTermsLabel))),e.When(I.errorVisible,()=>e.html.div(e.attr.class("bc-auth-form__field-error"),I.error.map(g=>g||"")))))),T.Button({type:"submit",variant:"filled",color:"primary",loading:h,disabled:k.disabledOrHasErrors},e.attr.class("bc-auth-form__submit"),e.coalesce(o?.signUpButton,L.$.signUpButton))))}function ee({onResetPassword:t,labels:o={}}){const r=H(),a=e.prop(!1),c=_.useForm({schema:j,onSubmit:E({task:t,message:"Reset password failed",onStart:()=>{a.set(!0),c.controller.disable()},onEnd:()=>{a.set(!1),c.controller.enable()}}),initialValue:{email:""}}),{controller:s,submit:u}=c;a.on(s.setDisabled);const n=s.field("email");return r.on(l=>{l!=null&&n.change(l)}),e.Use(m.AuthI18n,l=>e.html.form(e.attr.class("bc-auth-form__form"),e.Ensure(s.error,i=>y.Notice({variant:"danger",tone:"prominent",role:"alert"},e.html.div(i))),e.html.p(e.attr.class("bc-auth-form__description"),e.coalesce(o?.resetPasswordDescription,l.$.resetPasswordDescription)),e.on.submit(u),q.Stack(e.attr.class("bc-auth-form__fields"),_.Control(y.EmailInput,{controller:n,label:e.coalesce(o?.emailLabel,l.$.emailLabel)})),T.Button({loading:a,type:"submit",variant:"filled",color:"primary",disabled:s.disabledOrHasErrors},e.attr.class("bc-auth-form__submit"),e.coalesce(o?.resetPasswordButton,l.$.resetPasswordButton))))}function p({provider:t,onClick:o,size:r="md",name:a,icon:c,color:s,flow:u,labels:n}){const l=async()=>{if(o)try{u==="popup"?await o():await o()}catch(i){console.error(`Social login error for ${t} (${u||"redirect"} flow):`,i)}};return T.Button({type:"button",variant:"filled",size:r,color:s,onClick:l,roundedness:"full"},e.attr.class("bc-social-login-button"),e.attr.class(e.computedOf(t)(i=>`bc-social-login-button--${i}`)),e.html.span(e.attr.class("bc-social-login-button__inner"),e.html.span(e.attr.class("bc-social-login-button__icon"),ne.Icon({icon:c,size:r},e.attr.class("bc-social-login-button__icon-inner"))),e.Use(m.AuthI18n,i=>e.html.span(e.attr.class("bc-social-login-button__label"),e.bind(e.coalesce(n?.continueWithProvider,i.$.continueWithProvider))(a)))))}function te({providers:t,onProviderClick:o,size:r="md",className:a}){return q.Stack(e.attr.class("bc-social-login-buttons"),e.attr.class(a),e.ForEach(t,c=>p({provider:c.$.provider,flow:c.$.flow,color:c.map(({provider:s})=>d[s].color),name:c.map(({provider:s})=>d[s].name),icon:c.map(({provider:s})=>d[s].icon),onClick:async()=>{o&&await o(c.$.provider.value)},size:r})))}const d={google:{name:"Google",icon:"logos:google-icon",color:"red"},github:{name:"GitHub",icon:"logos:github-icon",color:"black"},apple:{name:"Apple",icon:"logos:apple",color:"stone"},facebook:{name:"Facebook",icon:"logos:facebook",color:"blue"},twitter:{name:"Twitter",icon:"logos:twitter",color:"sky"},x:{name:"X",icon:"logos:x",color:"zinc"},microsoft:{name:"Microsoft",icon:"logos:microsoft-icon",color:"amber"},discord:{name:"Discord",icon:"logos:discord-icon",color:"indigo"},linkedin:{name:"LinkedIn",icon:"logos:linkedin-icon",color:"cyan"},instagram:{name:"Instagram",icon:"logos:instagram-icon",color:"fuchsia"},tiktok:{name:"TikTok",icon:"logos:tiktok-icon",color:"teal"},snapchat:{name:"Snapchat",icon:"simple-icons:snapchat",color:"yellow"},reddit:{name:"Reddit",icon:"logos:reddit-icon",color:"orange"},pinterest:{name:"Pinterest",icon:"logos:pinterest",color:"rose"},twitch:{name:"Twitch",icon:"logos:twitch",color:"purple"},steam:{name:"Steam",icon:"logos:steam",color:"slate"},epic:{name:"Epic Games",icon:"simple-icons:epicgames",color:"neutral"},playstation:{name:"PlayStation",icon:"simple-icons:playstation",color:"violet"},xbox:{name:"Xbox",icon:"simple-icons:xbox",color:"green"},whatsapp:{name:"WhatsApp",icon:"logos:whatsapp-icon",color:"emerald"},wechat:{name:"WeChat",icon:"simple-icons:wechat",color:"lime"},amazon:{name:"Amazon",icon:"simple-icons:amazon",color:"red"},yahoo:{name:"Yahoo",icon:"logos:yahoo",color:"rose"},paypal:{name:"PayPal",icon:"logos:paypal",color:"blue"}},ve=t=>p({...t,...d.google,provider:"google"}),ke=t=>p({...t,...d.github,provider:"github"}),Se=t=>p({...t,...d.apple,provider:"apple"}),Pe=t=>p({...t,...d.facebook,provider:"facebook"}),ye=t=>p({...t,...d.x,provider:"x"}),Be=t=>p({...t,...d.twitter,provider:"twitter"}),qe=t=>p({...t,...d.microsoft,provider:"microsoft"}),Ie=t=>p({...t,...d.discord,provider:"discord"}),xe=t=>p({...t,...d.linkedin,provider:"linkedin"}),Ae=t=>p({...t,...d.instagram,provider:"instagram"}),Ce=t=>p({...t,...d.tiktok,provider:"tiktok"}),Te=t=>p({...t,...d.snapchat,provider:"snapchat"}),$e=t=>p({...t,...d.reddit,provider:"reddit"}),Ee=t=>p({...t,...d.pinterest,provider:"pinterest"}),Me=t=>p({...t,...d.twitch,provider:"twitch"}),ze=t=>p({...t,...d.steam,provider:"steam"}),Ue=t=>p({...t,...d.epic,provider:"epic"}),Re=t=>p({...t,...d.playstation,provider:"playstation"}),Oe=t=>p({...t,...d.xbox,provider:"xbox"}),We=t=>p({...t,...d.whatsapp,provider:"whatsapp"}),Fe=t=>p({...t,...d.wechat,provider:"wechat"}),Ve=t=>p({...t,...d.amazon,provider:"amazon"}),Ne=t=>p({...t,...d.yahoo,provider:"yahoo"}),De=t=>p({...t,...d.paypal,provider:"paypal"});function N({providers:t,onSocialLogin:o}){return q.Stack(te({providers:t,onProviderClick:o}))}function oe({mode:t,socialProviders:o,initialName:r,initialEmail:a,passwordRules:c,showRememberMe:s,showSocialDivider:u,showPasswordStrength:n,labels:l,onSignIn:i,onSignUp:h,onResetPassword:b,onModeChange:w,onSocialLogin:v,showContainer:O,showNameField:x,showConfirmPassword:k,showAcceptTermsAndConditions:W,termsAndConditions:F},...V){const P=t!=null?e.Value.deriveProp(t):e.prop("signin");return P.on(S=>w?.(S)),e.Use(m.AuthI18n,S=>{function I(){const A=e.coalesce(l?.hasAccountLink,S.$.hasAccountLink);return e.html.button(e.attr.type("button"),e.attr.class("bc-auth-form__link"),e.on.click(()=>P.set("signin")),A)}function L(){return e.html.button(e.attr.type("button"),e.attr.class("bc-auth-form__link"),e.on.click(()=>P.set("signup")),e.coalesce(l?.noAccountLink,S.$.noAccountLink))}function g(){return e.html.button(e.attr.type("button"),e.attr.class("bc-auth-form__link"),e.on.click(()=>P.set("reset-password")),e.coalesce(l?.forgotPasswordLink,S.$.forgotPasswordLink))}return e.html.div(re.classes({"bc-auth-container":!0,"bc-auth-container--styled":e.Value.map(O??!0,A=>A)}),e.attr.class(P.map(A=>`bc-auth-container--${A}`)),e.attr.class("bc-auth-form"),e.OneOfValue(P,{signin:()=>e.Fragment(e.html.h2(e.attr.class("bc-auth-form__title"),e.coalesce(l?.signInTitle,S.$.signInTitle)),o!=null?e.Fragment(N({providers:o,onSocialLogin:v}),e.When(u??!1,D)):null,J({onSignIn:i,showRememberMe:s,passwordRules:c,labels:{emailLabel:l?.emailLabel,passwordLabel:l?.passwordLabel,rememberMeLabel:l?.rememberMeLabel,signInButton:l?.signInButton,forgotPasswordLink:l?.forgotPasswordLink,noAccountLink:l?.noAccountLink}}),q.Stack(e.attr.class("bc-auth-form__footer"),L(),g())),signup:()=>e.Fragment(e.html.h2(e.attr.class("bc-auth-form__title"),e.coalesce(l?.signUpTitle,S.$.signUpTitle)),o!=null?e.Fragment(N({providers:o,onSocialLogin:v}),e.When(u??!1,D)):null,Q({labels:{nameLabel:l?.nameLabel,emailLabel:l?.emailLabel,passwordLabel:l?.passwordLabel,confirmPasswordLabel:l?.confirmPasswordLabel,acceptTermsLabel:l?.acceptTermsLabel,signUpButton:l?.signUpButton,hasAccountLink:l?.hasAccountLink},initialEmail:a,initialName:r,onSignUp:h,passwordRules:c,showPasswordStrength:n,showNameField:x,showConfirmPassword:k,showAcceptTermsAndConditions:W,termsAndConditions:F}),q.Stack(e.attr.class("bc-auth-form__footer"),I())),"reset-password":()=>e.Fragment(e.html.h2(e.attr.class("bc-auth-form__title"),e.coalesce(l?.resetPasswordTitle,S.$.resetPasswordTitle)),ee({labels:{backToSignInLink:l?.backToSignInLink,emailLabel:l?.emailLabel,resetPasswordButton:l?.resetPasswordButton,resetPasswordDescription:l?.resetPasswordDescription},onResetPassword:b}),q.Stack(e.attr.class("bc-auth-form__footer"),I()))}),...V)})}function Ge(t){return f.Modal({size:"sm",dismissable:!0,showCloseButton:!0},(o,r)=>t(a=>o({body:oe({showContainer:!1,...a}),header:e.Use(m.AuthI18n,c=>e.coalesce(a.modalTitle,c.$.authenticationTitle))})))}function D({labels:t,className:o}={}){return e.html.div(e.attr.class("bc-auth-divider"),e.attr.class(o),e.html.div(e.attr.class("bc-auth-divider__line")),e.Use(m.AuthI18n,r=>e.html.span(e.attr.class("bc-auth-divider__text"),e.coalesce(t?.text,r.$.orDivider))),e.html.div(e.attr.class("bc-auth-divider__line")))}exports.AmazonLoginButton=Ve;exports.AppleLoginButton=Se;exports.AuthContainer=oe;exports.AuthDivider=D;exports.AuthModal=Ge;exports.DiscordLoginButton=Ie;exports.EpicLoginButton=Ue;exports.FacebookLoginButton=Pe;exports.GitHubLoginButton=ke;exports.GoogleLoginButton=ve;exports.InstagramLoginButton=Ae;exports.LinkedInLoginButton=xe;exports.MicrosoftLoginButton=qe;exports.PasswordStrengthBar=Le;exports.PasswordStrengthIndicator=K;exports.PasswordStrengthText=_e;exports.PayPalLoginButton=De;exports.PinterestLoginButton=Ee;exports.PlayStationLoginButton=Re;exports.RedditLoginButton=$e;exports.ResetPasswordForm=ee;exports.SignInForm=J;exports.SignUpForm=Q;exports.SnapchatLoginButton=Te;exports.SocialLoginButton=p;exports.SocialLoginButtons=te;exports.SocialProviders=N;exports.SteamLoginButton=ze;exports.TiktokLoginButton=Ce;exports.TwitchLoginButton=Me;exports.TwitterLoginButton=Be;exports.WeChatLoginButton=Fe;exports.WhatsAppLoginButton=We;exports.XLoginButtin=ye;exports.XboxLoginButton=Oe;exports.YahooLoginButton=Ne;exports.authSchemas=fe;exports.calculatePasswordStrength=R;exports.createEmailSchema=C;exports.createPasswordSchema=M;exports.createSignInSchema=z;exports.createSignUpSchema=U;exports.createSocialLoginUrl=ue;exports.defaultPasswordRules=B;exports.defaultSignInSchema=he;exports.defaultSignUpSchema=ge;exports.emailSchema=G;exports.formatAuthError=de;exports.formatProviderName=Y;exports.formatSocialLoginText=ce;exports.generateRandomString=Z;exports.getProviderColor=ie;exports.getProviderIcon=se;exports.isBrowser=pe;exports.isValidEmail=le;exports.openSocialLoginPopup=me;exports.providerInfo=$;exports.requestToControllerValidation=E;exports.resetPasswordSchema=j;exports.socialProviderInfo=d;exports.useAuthEmailProp=H;exports.validateEmail=be;exports.validatePassword=we;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@tempots/dom"),L=require("../auth-divider-DfWGT38w.cjs"),I=require("../translations-qefRsdGi.cjs"),w=require("../notice-Q0A1gIho.cjs"),y=require("../stack-dwLevGa2.cjs"),b=require("../input-container-BkPcNDaZ.cjs"),v=require("../text-input-D_IxFd0M.cjs");function g(a,t){return a.error?(t.onError?.({message:a.error.message,status:a.error.status}),a.error.message):null}function F(a,t,s){return async n=>{const i=await a.signIn.email({email:n.email,password:n.password,callbackURL:t.callbackURL}),o=g(i,t);return o||(await s(),null)}}function A(a,t,s){return async n=>{const i=await a.signUp.email({name:n.name,email:n.email,password:n.password,callbackURL:t.callbackURL}),o=g(i,t);return o||(await s(),null)}}function U(a,t){return async s=>{const n=await a.requestPasswordReset({email:s.email,redirectTo:t.callbackURL});return g(n,t)}}function $(a,t){return async s=>{const n=await a.signIn.social({provider:s,callbackURL:t.callbackURL,errorCallbackURL:t.errorCallbackURL});g(n,t)}}function P(a,t={}){const s=e.prop(null),n=e.prop(!0),i=e.computedOf(s)(h=>h?.user??null),o=e.computedOf(s)(h=>h!=null);let u;async function d(){try{const h=await a.getSession();h.error||!h.data?s.set(null):s.set({user:h.data.user,session:h.data.session})}catch{s.set(null)}finally{n.set(!1)}}t.onSessionChange&&s.on(t.onSessionChange),d(),t.refreshInterval&&t.refreshInterval>0&&(u=setInterval(d,t.refreshInterval));function p(){u!=null&&(clearInterval(u),u=void 0),s.dispose(),n.dispose(),i.dispose(),o.dispose()}return{session:s,isPending:n,user:i,isAuthenticated:o,refresh:d,dispose:p}}function _(a){return a.map(t=>({provider:t}))}function C(a,t={}){const s=P(a,{refreshInterval:t.refreshInterval,onSessionChange:t.onSessionChange}),n=()=>s.refresh(),i=F(a,t,n),o=A(a,t,n),u=U(a,t),d=$(a,t),p=t.socialProviders?_(t.socialProviders):[],h={onSignIn:i,passwordRules:t.passwordRules,showRememberMe:t.showRememberMe,labels:t.labels?{emailLabel:t.labels.emailLabel,passwordLabel:t.labels.passwordLabel,rememberMeLabel:t.labels.rememberMeLabel,signInButton:t.labels.signInButton,forgotPasswordLink:t.labels.forgotPasswordLink,noAccountLink:t.labels.noAccountLink}:void 0},c={onSignUp:o,passwordRules:t.passwordRules,showPasswordStrength:t.showPasswordStrength,showNameField:t.showNameField,showConfirmPassword:t.showConfirmPassword,labels:t.labels?{nameLabel:t.labels.nameLabel,emailLabel:t.labels.emailLabel,passwordLabel:t.labels.passwordLabel,confirmPasswordLabel:t.labels.confirmPasswordLabel,acceptTermsLabel:t.labels.acceptTermsLabel,signUpButton:t.labels.signUpButton,hasAccountLink:t.labels.hasAccountLink}:void 0},m={onResetPassword:u,labels:t.labels?{resetPasswordButton:t.labels.resetPasswordButton,resetPasswordDescription:t.labels.resetPasswordDescription,emailLabel:t.labels.emailLabel,backToSignInLink:t.labels.backToSignInLink}:void 0},l={onSignIn:i,onSignUp:o,onResetPassword:u,onSocialLogin:d,socialProviders:p.length>0?p:void 0,showSocialDivider:p.length>0,passwordRules:t.passwordRules,showRememberMe:t.showRememberMe,showPasswordStrength:t.showPasswordStrength,showNameField:t.showNameField,showConfirmPassword:t.showConfirmPassword,labels:t.labels};async function r(){await a.signOut(),await n()}function f(){s.dispose()}return{session:s.session,isPending:s.isPending,user:s.user,isAuthenticated:s.isAuthenticated,containerOptions:l,signInOptions:h,signUpOptions:c,resetOptions:m,socialProviders:p,signOut:r,refreshSession:n,dispose:f}}const R={mark:e.makeProviderMark("BetterAuth"),create:a=>{if(!a)throw new Error("BetterAuth provider requires a client option");const t=C(a.client,a);return{value:t,dispose:()=>t.dispose()}}};function E(a,t,...s){return L.AuthContainer({...a.containerOptions,...t},...s)}function O(a,t){return L.AuthModal(s=>t(n=>s({...a.containerOptions,...n})))}function M(a,t){return e.When(a.isAuthenticated,t)}function D(a,t){return e.Unless(a.isAuthenticated,t)}const T={twoFactorSetupDescription:"Enter your password to enable two-factor authentication.",twoFactorEnableButton:"Enable 2FA",twoFactorVerifyButton:"Verify",twoFactorScanDescription:"Scan the code below with your authenticator app, then enter the verification code.",twoFactorBackupCodesDescription:"Save these backup codes in a safe place. You can use them to sign in if you lose access to your authenticator.",twoFactorCodePlaceholder:"Enter 6-digit code",twoFactorBackupCodePlaceholder:"Enter backup code",twoFactorEnabled:"Two-factor authentication has been enabled.",twoFactorTotpDescription:"Enter the code from your authenticator app.",twoFactorOtpDescription:"Enter the one-time code sent to you.",twoFactorBackupDescription:"Enter one of your backup codes.",twoFactorSendOtpButton:"Send Code",twoFactorMethodLabel:a=>{switch(a){case"totp":return"Authenticator";case"otp":return"Email/SMS";case"backup":return"Backup Code";default:return a}},passwordPlaceholder:"Enter your password",magicLinkDescription:"Enter your email to receive a sign-in link.",magicLinkSendButton:"Send Magic Link",magicLinkSent:"A sign-in link has been sent to your email.",passkeySignInButton:"Sign in with Passkey",passkeyAddButton:"Add Passkey",passkeyDeleteButton:"Delete",passkeyRenameButton:"Rename",passkeySaveButton:"Save",passkeyCancelButton:"Cancel",passkeyNamePlaceholder:"Passkey name (optional)",passkeyUnnamed:"Unnamed passkey"},B=T,S="en",N=Object.assign({}),k=I.makeI18nProvider({defaultLocale:S,defaultMessages:B,localeLoader:async a=>{if(a===S)return B;const t=N[`./locales/${a}.ts`];return t?await t():B},providerName:"BetterAuthI18n"});function q({twoFactor:a,issuer:t,onComplete:s}){const n=e.prop(""),i=e.prop(null),o=e.prop([]),u=e.prop(""),d=e.prop(null),p=e.prop(!1),h=e.prop("password");async function c(l){l.preventDefault(),p.set(!0),d.set(null);const r=await a.enable({password:n.value,issuer:t});if(p.set(!1),r.error){d.set(r.error.message);return}r.data&&(i.set(r.data.totpURI),o.set(r.data.backupCodes),h.set("verify"))}async function m(l){l.preventDefault(),p.set(!0),d.set(null);const r=await a.verifyTotp({code:u.value});if(p.set(!1),r.error){d.set(r.error.message);return}h.set("complete"),s?.()}return e.Use(k,l=>e.html.div(e.attr.class("bc-two-factor"),e.Ensure(d,r=>w.Notice({variant:"danger",tone:"prominent",role:"alert"},e.html.div(r))),e.OneOfValue(h,{password:()=>e.html.form(e.attr.class("bc-two-factor__form"),e.on.submit(c),y.Stack(e.html.p(e.attr.class("bc-auth-form__description"),l.$.twoFactorSetupDescription),w.PasswordInput({value:n,onChange:r=>n.set(r),placeholder:l.$.passwordPlaceholder}),b.Button({type:"submit",variant:"filled",color:"primary",loading:p},e.attr.class("bc-auth-form__submit"),l.$.twoFactorEnableButton))),verify:()=>e.Fragment(e.Ensure(i,r=>e.html.div(e.attr.class("bc-two-factor__totp-uri"),e.html.p(l.$.twoFactorScanDescription),e.html.code(e.attr.class("bc-two-factor__code-display"),r))),e.NotEmpty(o,()=>e.html.div(e.attr.class("bc-two-factor__backup-codes"),e.html.p(l.$.twoFactorBackupCodesDescription),e.html.ul(e.ForEach(o,r=>e.html.li(r))))),e.html.form(e.attr.class("bc-two-factor__form"),e.on.submit(m),y.Stack(v.TextInput({value:u,onChange:r=>u.set(r),placeholder:l.$.twoFactorCodePlaceholder}),b.Button({type:"submit",variant:"filled",color:"primary",loading:p},e.attr.class("bc-auth-form__submit"),l.$.twoFactorVerifyButton)))),complete:()=>e.html.div(e.attr.class("bc-two-factor__complete"),w.Notice({variant:"success",tone:"prominent"},e.html.div(l.$.twoFactorEnabled)))})))}function x({twoFactor:a,methods:t=["totp","backup"],trustDevice:s,onVerified:n}){const i=e.prop(""),o=e.prop(null),u=e.prop(!1),d=e.prop(t[0]??"totp");async function p(c){c.preventDefault(),u.set(!0),o.set(null);const m=d.value;let l;if(m==="totp")l=await a.verifyTotp({code:i.value,trustDevice:s});else if(m==="otp"&&a.verifyOtp)l=await a.verifyOtp({code:i.value,trustDevice:s});else if(m==="backup")l=await a.verifyBackupCode({code:i.value});else{o.set("Unsupported verification method"),u.set(!1);return}if(u.set(!1),l.error){o.set(l.error.message);return}n?.()}async function h(){if(!a.sendOtp)return;u.set(!0),o.set(null);const c=await a.sendOtp({trustDevice:s});u.set(!1),c.error&&o.set(c.error.message)}return e.Use(k,c=>{const m=e.computedOf(d,c)((r,f)=>r==="totp"?f.twoFactorTotpDescription:r==="otp"?f.twoFactorOtpDescription:f.twoFactorBackupDescription),l=e.computedOf(d,c)((r,f)=>r==="backup"?f.twoFactorBackupCodePlaceholder:f.twoFactorCodePlaceholder);return e.html.div(e.attr.class("bc-two-factor"),e.Ensure(o,r=>w.Notice({variant:"danger",tone:"prominent",role:"alert"},e.html.div(r))),e.When(t.length>1,()=>e.html.div(e.attr.class("bc-two-factor__methods"),...t.map(r=>e.html.button(e.attr.type("button"),e.attr.class("bc-two-factor__method-button"),e.attr.class(d.map(f=>f===r?"bc-two-factor__method-button--active":"")),e.on.click(()=>{d.set(r),i.set(""),o.set(null)}),c.$.twoFactorMethodLabel.map(f=>f(r)))))),e.html.form(e.attr.class("bc-two-factor__form"),e.on.submit(p),y.Stack(e.html.p(e.attr.class("bc-auth-form__description"),m),e.When(d.map(r=>r==="otp"&&a.sendOtp!=null),()=>b.Button({type:"button",variant:"outline",color:"primary",onClick:h,loading:u},c.$.twoFactorSendOtpButton)),v.TextInput({value:i,onChange:r=>i.set(r),placeholder:l}),b.Button({type:"submit",variant:"filled",color:"primary",loading:u},e.attr.class("bc-auth-form__submit"),c.$.twoFactorVerifyButton))))})}function V({client:a,callbackURL:t}){const s=e.prop(""),n=e.prop(null),i=e.prop(!1),o=e.prop(!1);async function u(d){if(d.preventDefault(),!a.signIn.magicLink){n.set("Magic link sign-in is not configured");return}i.set(!0),n.set(null);const p=await a.signIn.magicLink({email:s.value,callbackURL:t});if(i.set(!1),p.error){n.set(p.error.message);return}o.set(!0)}return e.Use(k,d=>e.html.div(e.attr.class("bc-auth-form"),e.Ensure(n,p=>w.Notice({variant:"danger",tone:"prominent",role:"alert"},e.html.div(p))),e.Unless(o,()=>e.html.form(e.attr.class("bc-auth-form__form"),e.on.submit(u),y.Stack(e.attr.class("bc-auth-form__fields"),e.html.p(e.attr.class("bc-auth-form__description"),d.$.magicLinkDescription),w.EmailInput({value:s,onChange:p=>s.set(p)}),b.Button({type:"submit",variant:"filled",color:"primary",loading:i},e.attr.class("bc-auth-form__submit"),d.$.magicLinkSendButton)))),e.When(o,()=>w.Notice({variant:"success",tone:"prominent"},e.html.div(d.$.magicLinkSent)))))}function W({client:a,autoFill:t,onSuccess:s,onError:n}){const i=e.prop(!1);async function o(){if(!a.signIn.passkey)return;i.set(!0);const u=await a.signIn.passkey({autoFill:t});if(i.set(!1),u.error){n?.({message:u.error.message,status:u.error.status});return}s?.()}return e.Use(k,u=>b.Button({type:"button",variant:"outline",color:"primary",onClick:o,loading:i},e.attr.class("bc-passkey-signin"),u.$.passkeySignInButton))}function z({passkey:a}){const t=e.prop([]),s=e.prop(null),n=e.prop(!1),i=e.prop("");async function o(c,m){n.set(!0),s.set(null);const l=await c();if(n.set(!1),l.error){s.set(l.error.message);return}await m?.(l.data)}async function u(){await o(()=>a.listUserPasskeys(),c=>t.set(c??[]))}async function d(){const c=i.value||void 0;await o(()=>a.addPasskey({name:c}),async()=>{i.set(""),await u()})}async function p(c){await o(()=>a.deletePasskey({id:c}),()=>u())}async function h(c,m){await o(()=>a.updatePasskey({id:c,name:m}),()=>u())}return u(),e.Use(k,c=>e.html.div(e.attr.class("bc-passkey-management"),e.Ensure(s,m=>w.Notice({variant:"danger",tone:"prominent",role:"alert"},e.html.div(m))),e.html.div(e.attr.class("bc-passkey-list"),e.ForEach(t,m=>{const l=e.prop(!1),r=e.prop(m.$.name?.value??"");return e.html.div(e.attr.class("bc-passkey-item"),e.Unless(l,()=>e.html.div(e.attr.class("bc-passkey-item__info"),e.html.span(e.attr.class("bc-passkey-item__name"),m.$.name?.map(f=>f??c.$.passkeyUnnamed.value)??c.$.passkeyUnnamed),e.html.span(e.attr.class("bc-passkey-item__date"),m.$.createdAt))),e.When(l,()=>e.html.div(e.attr.class("bc-passkey-item__edit"),v.TextInput({value:r,onChange:f=>r.set(f)}))),e.html.div(e.attr.class("bc-passkey-item__actions"),e.Unless(l,()=>e.html.div(b.Button({type:"button",variant:"text",size:"sm",onClick:()=>{r.set(m.$.name?.value??""),l.set(!0)}},c.$.passkeyRenameButton),b.Button({type:"button",variant:"text",size:"sm",color:"danger",onClick:()=>p(m.$.id.value)},c.$.passkeyDeleteButton))),e.When(l,()=>e.html.div(b.Button({type:"button",variant:"text",size:"sm",onClick:async()=>{await h(m.$.id.value,r.value),l.set(!1)}},c.$.passkeySaveButton),b.Button({type:"button",variant:"text",size:"sm",onClick:()=>l.set(!1)},c.$.passkeyCancelButton)))))})),e.html.div(e.attr.class("bc-passkey-add"),y.Stack(v.TextInput({value:i,onChange:m=>i.set(m),placeholder:c.$.passkeyNamePlaceholder}),b.Button({type:"button",variant:"filled",color:"primary",onClick:d,loading:n},c.$.passkeyAddButton)))))}exports.Authenticated=M;exports.BetterAuth=R;exports.BetterAuthContainer=E;exports.BetterAuthI18n=k;exports.BetterAuthModal=O;exports.MagicLinkForm=V;exports.PasskeyManagement=z;exports.PasskeySignIn=W;exports.TwoFactorSetup=q;exports.TwoFactorVerify=x;exports.Unauthenticated=D;exports.createBetterAuthBridge=C;exports.createSessionManager=P;exports.mapSocialProviders=_;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@tempots/dom"),C=require("../auth-divider-itm5-j5G.cjs"),A=require("../translations-qefRsdGi.cjs"),w=require("../notice-Q0A1gIho.cjs"),y=require("../stack-dwLevGa2.cjs"),b=require("../input-container-BkPcNDaZ.cjs"),v=require("../text-input-D_IxFd0M.cjs");function g(a,t){return a.error?(t.onError?.({message:a.error.message,status:a.error.status}),a.error.message):null}function I(a,t,s){return async n=>{const l=await a.signIn.email({email:n.email,password:n.password,callbackURL:t.callbackURL}),o=g(l,t);return o||(await s(),null)}}function F(a,t,s){return async n=>{const l=await a.signUp.email({name:n.name,email:n.email,password:n.password,callbackURL:t.callbackURL}),o=g(l,t);return o||(await s(),null)}}function U(a,t){return async s=>{const n=await a.requestPasswordReset({email:s.email,redirectTo:t.callbackURL});return g(n,t)}}function $(a,t){return async s=>{const n=await a.signIn.social({provider:s,callbackURL:t.callbackURL,errorCallbackURL:t.errorCallbackURL});g(n,t)}}function L(a,t={}){const s=e.prop(null),n=e.prop(!0),l=e.computedOf(s)(h=>h?.user??null),o=e.computedOf(s)(h=>h!=null);let u;async function d(){try{const h=await a.getSession();h.error||!h.data?s.set(null):s.set({user:h.data.user,session:h.data.session})}catch{s.set(null)}finally{n.set(!1)}}t.onSessionChange&&s.on(t.onSessionChange),d(),t.refreshInterval&&t.refreshInterval>0&&(u=setInterval(d,t.refreshInterval));function p(){u!=null&&(clearInterval(u),u=void 0),s.dispose(),n.dispose(),l.dispose(),o.dispose()}return{session:s,isPending:n,user:l,isAuthenticated:o,refresh:d,dispose:p}}function P(a){return a.map(t=>({provider:t}))}function _(a,t={}){const s=L(a,{refreshInterval:t.refreshInterval,onSessionChange:t.onSessionChange}),n=()=>s.refresh(),l=I(a,t,n),o=F(a,t,n),u=U(a,t),d=$(a,t),p=t.socialProviders?P(t.socialProviders):[],h={onSignIn:l,passwordRules:t.passwordRules,showRememberMe:t.showRememberMe,labels:t.labels?{emailLabel:t.labels.emailLabel,passwordLabel:t.labels.passwordLabel,rememberMeLabel:t.labels.rememberMeLabel,signInButton:t.labels.signInButton,forgotPasswordLink:t.labels.forgotPasswordLink,noAccountLink:t.labels.noAccountLink}:void 0},i={onSignUp:o,passwordRules:t.passwordRules,showPasswordStrength:t.showPasswordStrength,showNameField:t.showNameField,showConfirmPassword:t.showConfirmPassword,showAcceptTermsAndConditions:t.showAcceptTermsAndConditions,termsAndConditions:t.termsAndConditions,labels:t.labels?{nameLabel:t.labels.nameLabel,emailLabel:t.labels.emailLabel,passwordLabel:t.labels.passwordLabel,confirmPasswordLabel:t.labels.confirmPasswordLabel,acceptTermsLabel:t.labels.acceptTermsLabel,signUpButton:t.labels.signUpButton,hasAccountLink:t.labels.hasAccountLink}:void 0},m={onResetPassword:u,labels:t.labels?{resetPasswordButton:t.labels.resetPasswordButton,resetPasswordDescription:t.labels.resetPasswordDescription,emailLabel:t.labels.emailLabel,backToSignInLink:t.labels.backToSignInLink}:void 0},c={onSignIn:l,onSignUp:o,onResetPassword:u,onSocialLogin:d,socialProviders:p.length>0?p:void 0,showSocialDivider:p.length>0,passwordRules:t.passwordRules,showRememberMe:t.showRememberMe,showPasswordStrength:t.showPasswordStrength,showNameField:t.showNameField,showConfirmPassword:t.showConfirmPassword,showAcceptTermsAndConditions:t.showAcceptTermsAndConditions,termsAndConditions:t.termsAndConditions,labels:t.labels};async function r(){await a.signOut(),await n()}function f(){s.dispose()}return{session:s.session,isPending:s.isPending,user:s.user,isAuthenticated:s.isAuthenticated,containerOptions:c,signInOptions:h,signUpOptions:i,resetOptions:m,socialProviders:p,signOut:r,refreshSession:n,dispose:f}}const R={mark:e.makeProviderMark("BetterAuth"),create:a=>{if(!a)throw new Error("BetterAuth provider requires a client option");const t=_(a.client,a);return{value:t,dispose:()=>t.dispose()}}};function E(a,t,...s){return C.AuthContainer({...a.containerOptions,...t},...s)}function O(a,t){return C.AuthModal(s=>t(n=>s({...a.containerOptions,...n})))}function M(a,t){return e.When(a.isAuthenticated,t)}function D(a,t){return e.Unless(a.isAuthenticated,t)}const T={twoFactorSetupDescription:"Enter your password to enable two-factor authentication.",twoFactorEnableButton:"Enable 2FA",twoFactorVerifyButton:"Verify",twoFactorScanDescription:"Scan the code below with your authenticator app, then enter the verification code.",twoFactorBackupCodesDescription:"Save these backup codes in a safe place. You can use them to sign in if you lose access to your authenticator.",twoFactorCodePlaceholder:"Enter 6-digit code",twoFactorBackupCodePlaceholder:"Enter backup code",twoFactorEnabled:"Two-factor authentication has been enabled.",twoFactorTotpDescription:"Enter the code from your authenticator app.",twoFactorOtpDescription:"Enter the one-time code sent to you.",twoFactorBackupDescription:"Enter one of your backup codes.",twoFactorSendOtpButton:"Send Code",twoFactorMethodLabel:a=>{switch(a){case"totp":return"Authenticator";case"otp":return"Email/SMS";case"backup":return"Backup Code";default:return a}},passwordPlaceholder:"Enter your password",magicLinkDescription:"Enter your email to receive a sign-in link.",magicLinkSendButton:"Send Magic Link",magicLinkSent:"A sign-in link has been sent to your email.",passkeySignInButton:"Sign in with Passkey",passkeyAddButton:"Add Passkey",passkeyDeleteButton:"Delete",passkeyRenameButton:"Rename",passkeySaveButton:"Save",passkeyCancelButton:"Cancel",passkeyNamePlaceholder:"Passkey name (optional)",passkeyUnnamed:"Unnamed passkey"},B=T,S="en",N=Object.assign({}),k=A.makeI18nProvider({defaultLocale:S,defaultMessages:B,localeLoader:async a=>{if(a===S)return B;const t=N[`./locales/${a}.ts`];return t?await t():B},providerName:"BetterAuthI18n"});function q({twoFactor:a,issuer:t,onComplete:s}){const n=e.prop(""),l=e.prop(null),o=e.prop([]),u=e.prop(""),d=e.prop(null),p=e.prop(!1),h=e.prop("password");async function i(c){c.preventDefault(),p.set(!0),d.set(null);const r=await a.enable({password:n.value,issuer:t});if(p.set(!1),r.error){d.set(r.error.message);return}r.data&&(l.set(r.data.totpURI),o.set(r.data.backupCodes),h.set("verify"))}async function m(c){c.preventDefault(),p.set(!0),d.set(null);const r=await a.verifyTotp({code:u.value});if(p.set(!1),r.error){d.set(r.error.message);return}h.set("complete"),s?.()}return e.Use(k,c=>e.html.div(e.attr.class("bc-two-factor"),e.Ensure(d,r=>w.Notice({variant:"danger",tone:"prominent",role:"alert"},e.html.div(r))),e.OneOfValue(h,{password:()=>e.html.form(e.attr.class("bc-two-factor__form"),e.on.submit(i),y.Stack(e.html.p(e.attr.class("bc-auth-form__description"),c.$.twoFactorSetupDescription),w.PasswordInput({value:n,onChange:r=>n.set(r),placeholder:c.$.passwordPlaceholder}),b.Button({type:"submit",variant:"filled",color:"primary",loading:p},e.attr.class("bc-auth-form__submit"),c.$.twoFactorEnableButton))),verify:()=>e.Fragment(e.Ensure(l,r=>e.html.div(e.attr.class("bc-two-factor__totp-uri"),e.html.p(c.$.twoFactorScanDescription),e.html.code(e.attr.class("bc-two-factor__code-display"),r))),e.NotEmpty(o,()=>e.html.div(e.attr.class("bc-two-factor__backup-codes"),e.html.p(c.$.twoFactorBackupCodesDescription),e.html.ul(e.ForEach(o,r=>e.html.li(r))))),e.html.form(e.attr.class("bc-two-factor__form"),e.on.submit(m),y.Stack(v.TextInput({value:u,onChange:r=>u.set(r),placeholder:c.$.twoFactorCodePlaceholder}),b.Button({type:"submit",variant:"filled",color:"primary",loading:p},e.attr.class("bc-auth-form__submit"),c.$.twoFactorVerifyButton)))),complete:()=>e.html.div(e.attr.class("bc-two-factor__complete"),w.Notice({variant:"success",tone:"prominent"},e.html.div(c.$.twoFactorEnabled)))})))}function x({twoFactor:a,methods:t=["totp","backup"],trustDevice:s,onVerified:n}){const l=e.prop(""),o=e.prop(null),u=e.prop(!1),d=e.prop(t[0]??"totp");async function p(i){i.preventDefault(),u.set(!0),o.set(null);const m=d.value;let c;if(m==="totp")c=await a.verifyTotp({code:l.value,trustDevice:s});else if(m==="otp"&&a.verifyOtp)c=await a.verifyOtp({code:l.value,trustDevice:s});else if(m==="backup")c=await a.verifyBackupCode({code:l.value});else{o.set("Unsupported verification method"),u.set(!1);return}if(u.set(!1),c.error){o.set(c.error.message);return}n?.()}async function h(){if(!a.sendOtp)return;u.set(!0),o.set(null);const i=await a.sendOtp({trustDevice:s});u.set(!1),i.error&&o.set(i.error.message)}return e.Use(k,i=>{const m=e.computedOf(d,i)((r,f)=>r==="totp"?f.twoFactorTotpDescription:r==="otp"?f.twoFactorOtpDescription:f.twoFactorBackupDescription),c=e.computedOf(d,i)((r,f)=>r==="backup"?f.twoFactorBackupCodePlaceholder:f.twoFactorCodePlaceholder);return e.html.div(e.attr.class("bc-two-factor"),e.Ensure(o,r=>w.Notice({variant:"danger",tone:"prominent",role:"alert"},e.html.div(r))),e.When(t.length>1,()=>e.html.div(e.attr.class("bc-two-factor__methods"),...t.map(r=>e.html.button(e.attr.type("button"),e.attr.class("bc-two-factor__method-button"),e.attr.class(d.map(f=>f===r?"bc-two-factor__method-button--active":"")),e.on.click(()=>{d.set(r),l.set(""),o.set(null)}),i.$.twoFactorMethodLabel.map(f=>f(r)))))),e.html.form(e.attr.class("bc-two-factor__form"),e.on.submit(p),y.Stack(e.html.p(e.attr.class("bc-auth-form__description"),m),e.When(d.map(r=>r==="otp"&&a.sendOtp!=null),()=>b.Button({type:"button",variant:"outline",color:"primary",onClick:h,loading:u},i.$.twoFactorSendOtpButton)),v.TextInput({value:l,onChange:r=>l.set(r),placeholder:c}),b.Button({type:"submit",variant:"filled",color:"primary",loading:u},e.attr.class("bc-auth-form__submit"),i.$.twoFactorVerifyButton))))})}function V({client:a,callbackURL:t}){const s=e.prop(""),n=e.prop(null),l=e.prop(!1),o=e.prop(!1);async function u(d){if(d.preventDefault(),!a.signIn.magicLink){n.set("Magic link sign-in is not configured");return}l.set(!0),n.set(null);const p=await a.signIn.magicLink({email:s.value,callbackURL:t});if(l.set(!1),p.error){n.set(p.error.message);return}o.set(!0)}return e.Use(k,d=>e.html.div(e.attr.class("bc-auth-form"),e.Ensure(n,p=>w.Notice({variant:"danger",tone:"prominent",role:"alert"},e.html.div(p))),e.Unless(o,()=>e.html.form(e.attr.class("bc-auth-form__form"),e.on.submit(u),y.Stack(e.attr.class("bc-auth-form__fields"),e.html.p(e.attr.class("bc-auth-form__description"),d.$.magicLinkDescription),w.EmailInput({value:s,onChange:p=>s.set(p)}),b.Button({type:"submit",variant:"filled",color:"primary",loading:l},e.attr.class("bc-auth-form__submit"),d.$.magicLinkSendButton)))),e.When(o,()=>w.Notice({variant:"success",tone:"prominent"},e.html.div(d.$.magicLinkSent)))))}function W({client:a,autoFill:t,onSuccess:s,onError:n}){const l=e.prop(!1);async function o(){if(!a.signIn.passkey)return;l.set(!0);const u=await a.signIn.passkey({autoFill:t});if(l.set(!1),u.error){n?.({message:u.error.message,status:u.error.status});return}s?.()}return e.Use(k,u=>b.Button({type:"button",variant:"outline",color:"primary",onClick:o,loading:l},e.attr.class("bc-passkey-signin"),u.$.passkeySignInButton))}function z({passkey:a}){const t=e.prop([]),s=e.prop(null),n=e.prop(!1),l=e.prop("");async function o(i,m){n.set(!0),s.set(null);const c=await i();if(n.set(!1),c.error){s.set(c.error.message);return}await m?.(c.data)}async function u(){await o(()=>a.listUserPasskeys(),i=>t.set(i??[]))}async function d(){const i=l.value||void 0;await o(()=>a.addPasskey({name:i}),async()=>{l.set(""),await u()})}async function p(i){await o(()=>a.deletePasskey({id:i}),()=>u())}async function h(i,m){await o(()=>a.updatePasskey({id:i,name:m}),()=>u())}return u(),e.Use(k,i=>e.html.div(e.attr.class("bc-passkey-management"),e.Ensure(s,m=>w.Notice({variant:"danger",tone:"prominent",role:"alert"},e.html.div(m))),e.html.div(e.attr.class("bc-passkey-list"),e.ForEach(t,m=>{const c=e.prop(!1),r=e.prop(m.$.name?.value??"");return e.html.div(e.attr.class("bc-passkey-item"),e.Unless(c,()=>e.html.div(e.attr.class("bc-passkey-item__info"),e.html.span(e.attr.class("bc-passkey-item__name"),m.$.name?.map(f=>f??i.$.passkeyUnnamed.value)??i.$.passkeyUnnamed),e.html.span(e.attr.class("bc-passkey-item__date"),m.$.createdAt))),e.When(c,()=>e.html.div(e.attr.class("bc-passkey-item__edit"),v.TextInput({value:r,onChange:f=>r.set(f)}))),e.html.div(e.attr.class("bc-passkey-item__actions"),e.Unless(c,()=>e.html.div(b.Button({type:"button",variant:"text",size:"sm",onClick:()=>{r.set(m.$.name?.value??""),c.set(!0)}},i.$.passkeyRenameButton),b.Button({type:"button",variant:"text",size:"sm",color:"danger",onClick:()=>p(m.$.id.value)},i.$.passkeyDeleteButton))),e.When(c,()=>e.html.div(b.Button({type:"button",variant:"text",size:"sm",onClick:async()=>{await h(m.$.id.value,r.value),c.set(!1)}},i.$.passkeySaveButton),b.Button({type:"button",variant:"text",size:"sm",onClick:()=>c.set(!1)},i.$.passkeyCancelButton)))))})),e.html.div(e.attr.class("bc-passkey-add"),y.Stack(v.TextInput({value:l,onChange:m=>l.set(m),placeholder:i.$.passkeyNamePlaceholder}),b.Button({type:"button",variant:"filled",color:"primary",onClick:d,loading:n},i.$.passkeyAddButton)))))}exports.Authenticated=M;exports.BetterAuth=R;exports.BetterAuthContainer=E;exports.BetterAuthI18n=k;exports.BetterAuthModal=O;exports.MagicLinkForm=V;exports.PasskeyManagement=z;exports.PasskeySignIn=W;exports.TwoFactorSetup=q;exports.TwoFactorVerify=x;exports.Unauthenticated=D;exports.createBetterAuthBridge=_;exports.createSessionManager=L;exports.mapSocialProviders=P;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { prop as b, computedOf as
|
|
2
|
-
import { b as M, d as T } from "../auth-divider-
|
|
1
|
+
import { prop as b, computedOf as _, makeProviderMark as U, When as y, Unless as B, Use as P, html as r, attr as l, Ensure as g, OneOfValue as D, Fragment as E, NotEmpty as O, ForEach as R, on as C } from "@tempots/dom";
|
|
2
|
+
import { b as M, d as T } from "../auth-divider-D_3gKZ6g.js";
|
|
3
3
|
import { m as N } from "../translations-DT5QQ4WO.js";
|
|
4
4
|
import { N as v, P as V, E as x } from "../notice-Du3tWJTW.js";
|
|
5
|
-
import { S as
|
|
5
|
+
import { S as L } from "../stack-BLMteGTn.js";
|
|
6
6
|
import { B as k } from "../input-container-CO3DNqpp.js";
|
|
7
|
-
import { T as
|
|
8
|
-
function
|
|
7
|
+
import { T as A } from "../text-input-BAn02BzO.js";
|
|
8
|
+
function I(t, e) {
|
|
9
9
|
return t.error ? (e.onError?.({
|
|
10
10
|
message: t.error.message,
|
|
11
11
|
status: t.error.status
|
|
@@ -17,7 +17,7 @@ function z(t, e, a) {
|
|
|
17
17
|
email: n.email,
|
|
18
18
|
password: n.password,
|
|
19
19
|
callbackURL: e.callbackURL
|
|
20
|
-
}), o =
|
|
20
|
+
}), o = I(u, e);
|
|
21
21
|
return o || (await a(), null);
|
|
22
22
|
};
|
|
23
23
|
}
|
|
@@ -28,7 +28,7 @@ function q(t, e, a) {
|
|
|
28
28
|
email: n.email,
|
|
29
29
|
password: n.password,
|
|
30
30
|
callbackURL: e.callbackURL
|
|
31
|
-
}), o =
|
|
31
|
+
}), o = I(u, e);
|
|
32
32
|
return o || (await a(), null);
|
|
33
33
|
};
|
|
34
34
|
}
|
|
@@ -38,7 +38,7 @@ function j(t, e) {
|
|
|
38
38
|
email: a.email,
|
|
39
39
|
redirectTo: e.callbackURL
|
|
40
40
|
});
|
|
41
|
-
return
|
|
41
|
+
return I(n, e);
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
function H(t, e) {
|
|
@@ -48,13 +48,13 @@ function H(t, e) {
|
|
|
48
48
|
callbackURL: e.callbackURL,
|
|
49
49
|
errorCallbackURL: e.errorCallbackURL
|
|
50
50
|
});
|
|
51
|
-
|
|
51
|
+
I(n, e);
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
function W(t, e = {}) {
|
|
55
|
-
const a = b(null), n = b(!0), u =
|
|
55
|
+
const a = b(null), n = b(!0), u = _(a)(
|
|
56
56
|
(w) => w?.user ?? null
|
|
57
|
-
), o =
|
|
57
|
+
), o = _(a)((w) => w != null);
|
|
58
58
|
let d;
|
|
59
59
|
async function m() {
|
|
60
60
|
try {
|
|
@@ -102,6 +102,8 @@ function G(t, e = {}) {
|
|
|
102
102
|
showPasswordStrength: e.showPasswordStrength,
|
|
103
103
|
showNameField: e.showNameField,
|
|
104
104
|
showConfirmPassword: e.showConfirmPassword,
|
|
105
|
+
showAcceptTermsAndConditions: e.showAcceptTermsAndConditions,
|
|
106
|
+
termsAndConditions: e.termsAndConditions,
|
|
105
107
|
labels: e.labels ? {
|
|
106
108
|
nameLabel: e.labels.nameLabel,
|
|
107
109
|
emailLabel: e.labels.emailLabel,
|
|
@@ -131,6 +133,8 @@ function G(t, e = {}) {
|
|
|
131
133
|
showPasswordStrength: e.showPasswordStrength,
|
|
132
134
|
showNameField: e.showNameField,
|
|
133
135
|
showConfirmPassword: e.showConfirmPassword,
|
|
136
|
+
showAcceptTermsAndConditions: e.showAcceptTermsAndConditions,
|
|
137
|
+
termsAndConditions: e.termsAndConditions,
|
|
134
138
|
labels: e.labels
|
|
135
139
|
};
|
|
136
140
|
async function s() {
|
|
@@ -178,7 +182,7 @@ function ie(t, e) {
|
|
|
178
182
|
return y(t.isAuthenticated, e);
|
|
179
183
|
}
|
|
180
184
|
function ce(t, e) {
|
|
181
|
-
return
|
|
185
|
+
return B(t.isAuthenticated, e);
|
|
182
186
|
}
|
|
183
187
|
const J = {
|
|
184
188
|
// Two-Factor Authentication
|
|
@@ -220,13 +224,13 @@ const J = {
|
|
|
220
224
|
passkeyCancelButton: "Cancel",
|
|
221
225
|
passkeyNamePlaceholder: "Passkey name (optional)",
|
|
222
226
|
passkeyUnnamed: "Unnamed passkey"
|
|
223
|
-
},
|
|
224
|
-
defaultLocale:
|
|
225
|
-
defaultMessages:
|
|
227
|
+
}, F = J, $ = "en", K = /* @__PURE__ */ Object.assign({}), S = N({
|
|
228
|
+
defaultLocale: $,
|
|
229
|
+
defaultMessages: F,
|
|
226
230
|
localeLoader: async (t) => {
|
|
227
|
-
if (t ===
|
|
231
|
+
if (t === $) return F;
|
|
228
232
|
const e = K[`./locales/${t}.ts`];
|
|
229
|
-
return e ? await e() :
|
|
233
|
+
return e ? await e() : F;
|
|
230
234
|
},
|
|
231
235
|
providerName: "BetterAuthI18n"
|
|
232
236
|
});
|
|
@@ -257,8 +261,8 @@ function le({
|
|
|
257
261
|
}
|
|
258
262
|
w.set("complete"), a?.();
|
|
259
263
|
}
|
|
260
|
-
return
|
|
261
|
-
|
|
264
|
+
return P(
|
|
265
|
+
S,
|
|
262
266
|
(i) => r.div(
|
|
263
267
|
l.class("bc-two-factor"),
|
|
264
268
|
g(
|
|
@@ -271,8 +275,8 @@ function le({
|
|
|
271
275
|
D(w, {
|
|
272
276
|
password: () => r.form(
|
|
273
277
|
l.class("bc-two-factor__form"),
|
|
274
|
-
|
|
275
|
-
|
|
278
|
+
C.submit(c),
|
|
279
|
+
L(
|
|
276
280
|
r.p(
|
|
277
281
|
l.class("bc-auth-form__description"),
|
|
278
282
|
i.$.twoFactorSetupDescription
|
|
@@ -308,14 +312,14 @@ function le({
|
|
|
308
312
|
() => r.div(
|
|
309
313
|
l.class("bc-two-factor__backup-codes"),
|
|
310
314
|
r.p(i.$.twoFactorBackupCodesDescription),
|
|
311
|
-
r.ul(
|
|
315
|
+
r.ul(R(o, (s) => r.li(s)))
|
|
312
316
|
)
|
|
313
317
|
),
|
|
314
318
|
r.form(
|
|
315
319
|
l.class("bc-two-factor__form"),
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
320
|
+
C.submit(p),
|
|
321
|
+
L(
|
|
322
|
+
A({
|
|
319
323
|
value: d,
|
|
320
324
|
onChange: (s) => d.set(s),
|
|
321
325
|
placeholder: i.$.twoFactorCodePlaceholder
|
|
@@ -383,11 +387,11 @@ function ue({
|
|
|
383
387
|
const c = await t.sendOtp({ trustDevice: a });
|
|
384
388
|
d.set(!1), c.error && o.set(c.error.message);
|
|
385
389
|
}
|
|
386
|
-
return S
|
|
387
|
-
const p =
|
|
390
|
+
return P(S, (c) => {
|
|
391
|
+
const p = _(
|
|
388
392
|
m,
|
|
389
393
|
c
|
|
390
|
-
)((s, h) => s === "totp" ? h.twoFactorTotpDescription : s === "otp" ? h.twoFactorOtpDescription : h.twoFactorBackupDescription), i =
|
|
394
|
+
)((s, h) => s === "totp" ? h.twoFactorTotpDescription : s === "otp" ? h.twoFactorOtpDescription : h.twoFactorBackupDescription), i = _(
|
|
391
395
|
m,
|
|
392
396
|
c
|
|
393
397
|
)((s, h) => s === "backup" ? h.twoFactorBackupCodePlaceholder : h.twoFactorCodePlaceholder);
|
|
@@ -414,7 +418,7 @@ function ue({
|
|
|
414
418
|
(h) => h === s ? "bc-two-factor__method-button--active" : ""
|
|
415
419
|
)
|
|
416
420
|
),
|
|
417
|
-
|
|
421
|
+
C.click(() => {
|
|
418
422
|
m.set(s), u.set(""), o.set(null);
|
|
419
423
|
}),
|
|
420
424
|
c.$.twoFactorMethodLabel.map((h) => h(s))
|
|
@@ -424,8 +428,8 @@ function ue({
|
|
|
424
428
|
),
|
|
425
429
|
r.form(
|
|
426
430
|
l.class("bc-two-factor__form"),
|
|
427
|
-
|
|
428
|
-
|
|
431
|
+
C.submit(f),
|
|
432
|
+
L(
|
|
429
433
|
r.p(l.class("bc-auth-form__description"), p),
|
|
430
434
|
// Send OTP button (only for OTP method)
|
|
431
435
|
y(
|
|
@@ -441,7 +445,7 @@ function ue({
|
|
|
441
445
|
c.$.twoFactorSendOtpButton
|
|
442
446
|
)
|
|
443
447
|
),
|
|
444
|
-
|
|
448
|
+
A({
|
|
445
449
|
value: u,
|
|
446
450
|
onChange: (s) => u.set(s),
|
|
447
451
|
placeholder: i
|
|
@@ -482,8 +486,8 @@ function de({
|
|
|
482
486
|
}
|
|
483
487
|
o.set(!0);
|
|
484
488
|
}
|
|
485
|
-
return
|
|
486
|
-
|
|
489
|
+
return P(
|
|
490
|
+
S,
|
|
487
491
|
(m) => r.div(
|
|
488
492
|
l.class("bc-auth-form"),
|
|
489
493
|
g(
|
|
@@ -493,12 +497,12 @@ function de({
|
|
|
493
497
|
r.div(f)
|
|
494
498
|
)
|
|
495
499
|
),
|
|
496
|
-
|
|
500
|
+
B(
|
|
497
501
|
o,
|
|
498
502
|
() => r.form(
|
|
499
503
|
l.class("bc-auth-form__form"),
|
|
500
|
-
|
|
501
|
-
|
|
504
|
+
C.submit(d),
|
|
505
|
+
L(
|
|
502
506
|
l.class("bc-auth-form__fields"),
|
|
503
507
|
r.p(
|
|
504
508
|
l.class("bc-auth-form__description"),
|
|
@@ -548,8 +552,8 @@ function me({
|
|
|
548
552
|
}
|
|
549
553
|
a?.();
|
|
550
554
|
}
|
|
551
|
-
return
|
|
552
|
-
|
|
555
|
+
return P(
|
|
556
|
+
S,
|
|
553
557
|
(d) => k(
|
|
554
558
|
{
|
|
555
559
|
type: "button",
|
|
@@ -603,8 +607,8 @@ function fe({
|
|
|
603
607
|
() => d()
|
|
604
608
|
);
|
|
605
609
|
}
|
|
606
|
-
return d(),
|
|
607
|
-
|
|
610
|
+
return d(), P(
|
|
611
|
+
S,
|
|
608
612
|
(c) => r.div(
|
|
609
613
|
l.class("bc-passkey-management"),
|
|
610
614
|
g(
|
|
@@ -617,11 +621,11 @@ function fe({
|
|
|
617
621
|
// Passkey list
|
|
618
622
|
r.div(
|
|
619
623
|
l.class("bc-passkey-list"),
|
|
620
|
-
|
|
624
|
+
R(e, (p) => {
|
|
621
625
|
const i = b(!1), s = b(p.$.name?.value ?? "");
|
|
622
626
|
return r.div(
|
|
623
627
|
l.class("bc-passkey-item"),
|
|
624
|
-
|
|
628
|
+
B(
|
|
625
629
|
i,
|
|
626
630
|
() => r.div(
|
|
627
631
|
l.class("bc-passkey-item__info"),
|
|
@@ -636,7 +640,7 @@ function fe({
|
|
|
636
640
|
i,
|
|
637
641
|
() => r.div(
|
|
638
642
|
l.class("bc-passkey-item__edit"),
|
|
639
|
-
|
|
643
|
+
A({
|
|
640
644
|
value: s,
|
|
641
645
|
onChange: (h) => s.set(h)
|
|
642
646
|
})
|
|
@@ -644,7 +648,7 @@ function fe({
|
|
|
644
648
|
),
|
|
645
649
|
r.div(
|
|
646
650
|
l.class("bc-passkey-item__actions"),
|
|
647
|
-
|
|
651
|
+
B(
|
|
648
652
|
i,
|
|
649
653
|
() => r.div(
|
|
650
654
|
k(
|
|
@@ -702,8 +706,8 @@ function fe({
|
|
|
702
706
|
// Add passkey
|
|
703
707
|
r.div(
|
|
704
708
|
l.class("bc-passkey-add"),
|
|
705
|
-
|
|
706
|
-
|
|
709
|
+
L(
|
|
710
|
+
A({
|
|
707
711
|
value: u,
|
|
708
712
|
onChange: (p) => u.set(p),
|
|
709
713
|
placeholder: c.$.passkeyNamePlaceholder
|
|
@@ -727,7 +731,7 @@ export {
|
|
|
727
731
|
ie as Authenticated,
|
|
728
732
|
ne as BetterAuth,
|
|
729
733
|
re as BetterAuthContainer,
|
|
730
|
-
|
|
734
|
+
S as BetterAuthI18n,
|
|
731
735
|
oe as BetterAuthModal,
|
|
732
736
|
de as MagicLinkForm,
|
|
733
737
|
fe as PasskeyManagement,
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @module better-auth/types
|
|
10
10
|
*/
|
|
11
|
-
import { Signal } from '@tempots/dom';
|
|
11
|
+
import { Signal, TNode } from '@tempots/dom';
|
|
12
12
|
import { AuthContainerLabels, AuthContainerOptions, AuthProviderInfo, AuthProviderName, PasswordRules, ResetPasswordFormOptions, SignInFormOptions, SignUpFormOptions } from '../components/auth';
|
|
13
13
|
/**
|
|
14
14
|
* Structural interface for the better-auth client.
|
|
@@ -199,6 +199,10 @@ export interface BetterAuthBridgeOptions {
|
|
|
199
199
|
showNameField?: boolean;
|
|
200
200
|
/** Whether to show the confirm password field on the sign-up form. */
|
|
201
201
|
showConfirmPassword?: boolean;
|
|
202
|
+
/** Whether to show the "accept terms and conditions" checkbox on the sign-up form. */
|
|
203
|
+
showAcceptTermsAndConditions?: boolean;
|
|
204
|
+
/** Custom terms and conditions content to display next to the checkbox. */
|
|
205
|
+
termsAndConditions?: TNode;
|
|
202
206
|
/** Whether to show the password strength indicator on the sign-up form. */
|
|
203
207
|
showPasswordStrength?: boolean;
|
|
204
208
|
/** Session polling interval in milliseconds. Set to `0` to disable. @default 0 */
|
|
@@ -43,7 +43,7 @@ import { AuthContainerOptions } from './index';
|
|
|
43
43
|
* })
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
46
|
-
export declare function AuthContainer({ mode: initialMode, socialProviders, initialName, initialEmail, passwordRules, showRememberMe, showSocialDivider, showPasswordStrength, labels, onSignIn, onSignUp, onResetPassword, onModeChange, onSocialLogin, showContainer, }: AuthContainerOptions, ...children: TNode[]): import("@tempots/core").Renderable<import("@tempots/dom").DOMContext, typeof import("@tempots/dom").DOM_RENDERABLE_TYPE>;
|
|
46
|
+
export declare function AuthContainer({ mode: initialMode, socialProviders, initialName, initialEmail, passwordRules, showRememberMe, showSocialDivider, showPasswordStrength, labels, onSignIn, onSignUp, onResetPassword, onModeChange, onSocialLogin, showContainer, showNameField, showConfirmPassword, showAcceptTermsAndConditions, termsAndConditions, }: AuthContainerOptions, ...children: TNode[]): import("@tempots/core").Renderable<import("@tempots/dom").DOMContext, typeof import("@tempots/dom").DOM_RENDERABLE_TYPE>;
|
|
47
47
|
/**
|
|
48
48
|
* Creates an authentication container displayed inside a modal dialog.
|
|
49
49
|
*
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const e=require("@tempots/dom"),q=require("./stack-dwLevGa2.cjs"),L=require("./use-form-BvBkVEKi.cjs"),f=require("./modal-DCxNGrzk.cjs"),G=require("@tempots/std"),m=require("./translations-C_-cObaF.cjs"),P=require("./notice-Q0A1gIho.cjs"),C=require("./input-container-BkPcNDaZ.cjs"),ee=require("./text-input-D_IxFd0M.cjs"),te=require("./translations-qefRsdGi.cjs"),oe=require("@tempots/ui"),T={google:{name:"Google",icon:"logos:google-icon",color:"#4285f4"},github:{name:"GitHub",icon:"logos:github-icon",color:"#333"},apple:{name:"Apple",icon:"logos:apple",color:"#000"},facebook:{name:"Facebook",icon:"logos:facebook",color:"#1877f2"},twitter:{name:"Twitter",icon:"logos:twitter",color:"#1da1f2"},microsoft:{name:"Microsoft",icon:"logos:microsoft-icon",color:"#00a4ef"},discord:{name:"Discord",icon:"logos:discord-icon",color:"#5865f2"},linkedin:{name:"LinkedIn",icon:"logos:linkedin-icon",color:"#0077b5"},instagram:{name:"Instagram",icon:"logos:instagram-icon",color:"#e4405f"},tiktok:{name:"TikTok",icon:"logos:tiktok-icon",color:"#000"},snapchat:{name:"Snapchat",icon:"logos:snapchat-icon",color:"#fffc00"},reddit:{name:"Reddit",icon:"logos:reddit-icon",color:"#ff4500"},pinterest:{name:"Pinterest",icon:"logos:pinterest-icon",color:"#bd081c"},twitch:{name:"Twitch",icon:"logos:twitch",color:"#9146ff"},steam:{name:"Steam",icon:"logos:steam-icon",color:"#000"},epic:{name:"Epic Games",icon:"simple-icons:epicgames",color:"#313131"},playstation:{name:"PlayStation",icon:"logos:playstation-icon",color:"#003791"},xbox:{name:"Xbox",icon:"logos:xbox-icon",color:"#107c10"},whatsapp:{name:"WhatsApp",icon:"logos:whatsapp-icon",color:"#25d366"},wechat:{name:"WeChat",icon:"logos:wechat-icon",color:"#1aad19"},amazon:{name:"Amazon",icon:"logos:amazon-icon",color:"#ff9900"},yahoo:{name:"Yahoo",icon:"logos:yahoo-icon",color:"#720e9e"},paypal:{name:"PayPal",icon:"logos:paypal",color:"#0070ba"},x:{name:"X",icon:"simple-icons:x",color:"#000"}};function j(t){return T[t]?.name||t}function ae(t){return T[t]?.icon||"mdi:account"}function ne(t){return T[t]?.color||"#666"}function re(t,o="Continue with {provider}"){return o.replace("{provider}",j(t))}const y={minLength:8,requireUppercase:!0,requireLowercase:!0,requireNumbers:!0,requireSymbols:!1};function se(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}function H(t=32){const o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let n="";for(let a=0;a<t;a++)n+=o.charAt(Math.floor(Math.random()*o.length));return n}function ie(t,o,n,a=[],c={}){const s={google:"https://accounts.google.com/oauth/authorize",github:"https://github.com/login/oauth/authorize",apple:"https://appleid.apple.com/auth/authorize",facebook:"https://www.facebook.com/v18.0/dialog/oauth",twitter:"https://twitter.com/i/oauth2/authorize",microsoft:"https://login.microsoftonline.com/common/oauth2/v2.0/authorize",discord:"https://discord.com/api/oauth2/authorize",linkedin:"https://www.linkedin.com/oauth/v2/authorization",instagram:"https://api.instagram.com/oauth/authorize",tiktok:"https://www.tiktok.com/v2/auth/authorize",snapchat:"https://accounts.snapchat.com/accounts/oauth2/authorize",reddit:"https://www.reddit.com/api/v1/authorize",pinterest:"https://api.pinterest.com/oauth/",twitch:"https://id.twitch.tv/oauth2/authorize",steam:"https://steamcommunity.com/oauth/authorize",epic:"https://auth.epicgames.com/authorize",playstation:"https://auth.api.sonyentertainmentnetwork.com/oauth/authorize",xbox:"https://login.live.com/oauth20_authorize.srf",whatsapp:"https://web.whatsapp.com/oauth/authorize",wechat:"https://open.weixin.qq.com/connect/qrconnect",amazon:"https://www.amazon.com/ap/oa",yahoo:"https://api.login.yahoo.com/oauth2/request_auth",paypal:"https://www.paypal.com/signin/authorize",x:"https://api.twitter.com/oauth2/authorize"},u={google:["openid","email","profile"],github:["user:email"],apple:["email","name"],facebook:["email"],twitter:["users.read"],microsoft:["openid","email","profile"],discord:["identify","email"],linkedin:["r_liteprofile","r_emailaddress"],instagram:["user_profile","user_media"],tiktok:["user.info.basic","user.external.id"],snapchat:["user.info.basic","user.external.id"],reddit:["identity","email"],pinterest:["read_public","read_relationships"],twitch:["openid","email","profile"],steam:["openid","email","profile"],epic:["openid","email","profile"],playstation:["openid","email","profile"],xbox:["openid","email","profile"],whatsapp:["openid","email","profile"],wechat:["openid","email","profile"],amazon:["openid","email","profile"],yahoo:["openid","email","profile"],paypal:["openid","email","profile"],x:["openid","email","profile"]},r=s[t];if(!r)throw new Error(`Unsupported provider: ${t}`);const l=a.length>0?a:u[t],i=H(),h=new URLSearchParams({client_id:o,redirect_uri:n,scope:l.join(" "),state:i,response_type:"code",...c});return`${r}?${h.toString()}`}function ce(t,o,n,a){const c=window.open(t,`${o}_login`,"width=500,height=600,scrollbars=yes,resizable=yes");if(!c){a?.(new Error("Failed to open popup window"));return}const s=setInterval(()=>{c.closed&&(clearInterval(s),a?.(new Error("Login cancelled")))},1e3),u=r=>{r.origin===window.location.origin&&(r.data.type==="SOCIAL_LOGIN_SUCCESS"?(clearInterval(s),c.close(),window.removeEventListener("message",u),n?.(r.data.result)):r.data.type==="SOCIAL_LOGIN_ERROR"&&(clearInterval(s),c.close(),window.removeEventListener("message",u),a?.(new Error(r.data.error))))};window.addEventListener("message",u)}function le(t){return t instanceof Error?t.message:typeof t=="string"?t:t&&typeof t=="object"&&"message"in t?String(t.message):"An unexpected error occurred"}function ue(){return typeof window<"u"&&typeof document<"u"}function $({task:t,message:o,onStart:n,onEnd:a}){return async c=>{n?.();const s=await L.taskToValidation({task:t!=null?()=>t(c):async()=>null,errorMessage:o,errorPath:["root"],validation:u=>u!=null?G.Validation.invalid({message:u}):G.Validation.valid});return a?.(),s}}function E(t=y,o){const n=o??m.defaultMessages;let a=f.string();return t.minLength&&(a=a.min(t.minLength,(n.passwordMinLength??m.defaultMessages.passwordMinLength)(t.minLength))),t.requireUppercase&&(a=a.regex(/[A-Z]/,n.passwordRequireUppercase??m.defaultMessages.passwordRequireUppercase)),t.requireLowercase&&(a=a.regex(/[a-z]/,n.passwordRequireLowercase??m.defaultMessages.passwordRequireLowercase)),t.requireNumbers&&(a=a.regex(/[0-9]/,n.passwordRequireNumber??m.defaultMessages.passwordRequireNumber)),t.requireSymbols&&(a=a.regex(/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/,n.passwordRequireSpecialChar??m.defaultMessages.passwordRequireSpecialChar)),t.customValidation&&(a=a.refine(c=>t.customValidation(c))),a}function A(t){const o=t??m.defaultMessages;return f.string().min(1,o.emailRequired??m.defaultMessages.emailRequired).email(o.invalidEmail??m.defaultMessages.invalidEmail)}const V=A();function M(t,o){const n=o??m.defaultMessages,a=t?E(t,o):f.string().refine(c=>c.length>0?null:n.passwordRequired??m.defaultMessages.passwordRequired);return f.object({email:A(o),password:a,rememberMe:f.boolean().default(!1)}).schema()}function z(t=y,o,n){const a=n??m.defaultMessages,c=E(t,n),s=o?.showNameField!==!1,u=o?.showConfirmPassword!==!1,r=o?.showAcceptTermsAndConditions!==!1,l={name:s?f.string().min(1,a.nameRequired??m.defaultMessages.nameRequired).optional():f.string().optional(),email:A(n),password:c,confirmPassword:u?f.string().min(1,a.confirmPasswordRequired??m.defaultMessages.confirmPasswordRequired):f.string(),acceptTerms:r?f.boolean().refine(h=>h===!0,a.acceptTermsRequired??m.defaultMessages.acceptTermsRequired):f.boolean().default(!0)},i=f.object(l);return u?i.refine(h=>h.password===h.confirmPassword?null:a.passwordsDoNotMatch??m.defaultMessages.passwordsDoNotMatch,{path:["confirmPassword"]}).schema():i.schema()}const N=f.object({email:V}).schema(),me=M(),de=z(),pe={signIn:M,signUp:z,resetPassword:()=>N};function he(t,o){const n=o??m.defaultMessages,c=(o?A(o):V).validate(t);return c.success?null:c.errors[0]?.message||(n.invalidEmailAddress??m.defaultMessages.invalidEmailAddress)}function ge(t,o=y,n){const a=n??m.defaultMessages,s=E(o,n).validate(t);return s.success?null:s.errors[0]?.message||(a.invalidPassword??m.defaultMessages.invalidPassword)}function R(t,o=y){const n={length:t.length>=(o.minLength||8),uppercase:/[A-Z]/.test(t),lowercase:/[a-z]/.test(t),numbers:/[0-9]/.test(t),symbols:/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(t),custom:o.customValidation?o.customValidation(t)===null:t.length>0},a=[!0,o.requireUppercase,o.requireLowercase,o.requireNumbers,o.requireSymbols,!!o.customValidation].filter(Boolean).length,c=[n.length,o.requireUppercase?n.uppercase:null,o.requireLowercase?n.lowercase:null,o.requireNumbers?n.numbers:null,o.requireSymbols?n.symbols:null,o.customValidation?n.custom:null].filter(r=>r===!0).length,s=a>0?Math.round(c/a*100):0;let u;return s<40?u="weak":s<60?u="fair":s<80?u="good":u="strong",{strength:u,score:s,checks:n}}const D=()=>e.localStorageProp({key:"bui_auth_email",defaultValue:null});function X({onSignIn:t,passwordRules:o,labels:n,showRememberMe:a}){const c=e.prop(!1),s=D(),u=M(o),r=L.useForm({schema:u,onSubmit:$({task:t,message:"Reset password failed",onStart:()=>{c.set(!0),r.controller.disable()},onEnd:()=>{c.set(!1),r.controller.enable()}}),initialValue:{email:"",password:""}}),{controller:l,submit:i}=r;c.on(l.setDisabled);const h=l.field("email"),w=l.field("password");return s.on(b=>{b!=null&&h.change(b)}),h.signal.on(b=>{s.value!=null&&(s.value=b)}),e.Use(m.AuthI18n,b=>e.html.form(e.attr.class("bc-auth-form__form"),e.on.submit(i),q.Stack(e.attr.class("bc-auth-form__fields"),e.Ensure(l.error,_=>P.Notice({variant:"danger",tone:"prominent",role:"alert"},e.html.div(_))),L.Control(P.EmailInput,{controller:h,label:e.coalesce(n?.emailLabel,b.$.emailLabel)}),L.Control(P.PasswordInput,{controller:w,label:e.coalesce(n?.passwordLabel,b.$.passwordLabel)}),e.When(a??!0,()=>e.html.div(e.attr.class("bc-auth-form__remember-me"),e.html.label(e.attr.class("bc-auth-form__checkbox-label"),L.CheckboxInput({value:s.map(_=>_!=null),after:e.html.span(e.coalesce(n?.rememberMeLabel,b.$.rememberMeLabel)),onChange:_=>{_?s.value=h.signal.value??"":s.value=null}}))))),C.Button({type:"submit",variant:"filled",color:"primary",loading:c,disabled:l.disabledOrHasErrors},e.attr.class("bc-auth-form__submit"),e.coalesce(n?.signInButton,b.$.signInButton))))}function Y({password:t,rules:o=y,showLabel:n=!0,className:a}){const c=e.computedOf(t)(i=>!i||i.length===0?{strength:"weak",score:0,checks:{length:!1,uppercase:!1,lowercase:!1,numbers:!1,symbols:!1,custom:!1}}:R(i,o)),s=c.map(i=>i.strength),u=c.map(i=>i.score),r=c.map(i=>i.checks),l=e.computedOf(s,a)((i,h)=>["bc-password-strength",`bc-password-strength--${i}`,h].filter(Boolean).join(" "));return e.html.div(e.attr.class(l),e.html.div(e.attr.class("bc-password-strength__bar"),e.html.div(e.attr.class("bc-password-strength__fill"),e.attr.style(u.map(i=>`width: ${i}%`)))),e.When(n,()=>e.Use(m.AuthI18n,i=>e.html.div(e.attr.class("bc-password-strength__label"),e.computedOf(s,i)((h,w)=>{switch(h){case"weak":return w.passwordStrengthWeak;case"fair":return w.passwordStrengthFair;case"good":return w.passwordStrengthGood;case"strong":return w.passwordStrengthStrong;default:return w.passwordStrengthWeak}})))),e.html.div(e.attr.class("bc-password-strength__requirements"),e.When(o.minLength!==void 0,()=>e.html.div(e.attr.class("bc-password-strength__requirement"),e.attr.class(e.computedOf(r)(i=>i.length?"bc-password-strength__requirement--met":"")),e.html.span(e.attr.class("bc-password-strength__requirement-icon"),e.computedOf(r)(i=>i.length?"✓":"○")),e.html.span(e.attr.class("bc-password-strength__requirement-text"),`At least ${o.minLength} characters`))),e.When(o.requireUppercase===!0,()=>e.html.div(e.attr.class("bc-password-strength__requirement"),e.attr.class(e.computedOf(r)(i=>i.uppercase?"bc-password-strength__requirement--met":"")),e.html.span(e.attr.class("bc-password-strength__requirement-icon"),e.computedOf(r)(i=>i.uppercase?"✓":"○")),e.html.span(e.attr.class("bc-password-strength__requirement-text"),"One uppercase letter"))),e.When(o.requireLowercase===!0,()=>e.html.div(e.attr.class("bc-password-strength__requirement"),e.attr.class(e.computedOf(r)(i=>i.lowercase?"bc-password-strength__requirement--met":"")),e.html.span(e.attr.class("bc-password-strength__requirement-icon"),e.computedOf(r)(i=>i.lowercase?"✓":"○")),e.html.span(e.attr.class("bc-password-strength__requirement-text"),"One lowercase letter"))),e.When(o.requireNumbers===!0,()=>e.html.div(e.attr.class("bc-password-strength__requirement"),e.attr.class(e.computedOf(r)(i=>i.numbers?"bc-password-strength__requirement--met":"")),e.html.span(e.attr.class("bc-password-strength__requirement-icon"),e.computedOf(r)(i=>i.numbers?"✓":"○")),e.html.span(e.attr.class("bc-password-strength__requirement-text"),"One number"))),e.When(o.requireSymbols===!0,()=>e.html.div(e.attr.class("bc-password-strength__requirement"),e.attr.class(e.computedOf(r)(i=>i.symbols?"bc-password-strength__requirement--met":"")),e.html.span(e.attr.class("bc-password-strength__requirement-icon"),e.computedOf(r)(i=>i.symbols?"✓":"○")),e.html.span(e.attr.class("bc-password-strength__requirement-text"),"One special character")))))}function fe({password:t,rules:o=y,className:n}){const a=e.computedOf(t)(r=>!r||r.length===0?{strength:"weak",score:0}:R(r,o)),c=a.map(r=>r.strength),s=a.map(r=>r.score),u=e.computedOf(c,n)((r,l)=>["bc-password-strength-bar",`bc-password-strength-bar--${r}`,l].filter(Boolean).join(" "));return e.html.div(e.attr.class(u),e.html.div(e.attr.class("bc-password-strength-bar__fill"),e.attr.style(s.map(r=>`width: ${r}%`))))}function we({password:t,rules:o=y,className:n}){const a=e.computedOf(t)(s=>!s||s.length===0?"weak":R(s,o).strength),c=e.computedOf(a,n)((s,u)=>["bc-password-strength-text",`bc-password-strength-text--${s}`,u].filter(Boolean).join(" "));return e.Use(m.AuthI18n,s=>e.html.span(e.attr.class(c),e.computedOf(a,s)((u,r)=>{switch(u){case"weak":return r.passwordStrengthWeak;case"fair":return r.passwordStrengthFair;case"good":return r.passwordStrengthGood;case"strong":return r.passwordStrengthStrong;default:return r.passwordStrengthWeak}})))}function Z({passwordRules:t,labels:o,initialEmail:n,initialName:a,showPasswordStrength:c,onSignUp:s,showNameField:u,showConfirmPassword:r,showAcceptTermsAndConditions:l,termsAndConditions:i}){const h=e.prop(!1),w=t||y,b=z(w,{showNameField:u!==!1,showConfirmPassword:r!==!1,showAcceptTermsAndConditions:l!==!1}),_=L.useForm({schema:b,onSubmit:$({task:s!=null?g=>s({email:g.email,password:g.password,name:g.name,acceptTerms:g.acceptTerms}):void 0,message:"Reset password failed",onStart:()=>{h.set(!0),_.controller.disable()},onEnd:()=>{h.set(!1),_.controller.enable()}}),initialValue:{name:a??"",email:n??"",password:"",confirmPassword:"",acceptTerms:!1}}),{controller:v,submit:U}=_;h.on(v.setDisabled);const B=v.field("name"),S=v.field("email"),x=v.field("password"),O=v.field("confirmPassword"),I=v.field("acceptTerms");return e.Use(m.AuthI18n,g=>e.html.form(e.attr.class("bc-auth-form__form"),e.on.submit(U),q.Stack(e.attr.class("bc-auth-form__fields"),e.Ensure(v.error,k=>P.Notice({variant:"danger",tone:"prominent",role:"alert"},e.html.div(k))),e.When(u!==!1,()=>L.Control(ee.TextInput,{controller:B.transform(k=>k??"",k=>k===""?void 0:k),label:e.coalesce(o?.nameLabel,g.$.nameLabel)})),L.Control(P.EmailInput,{controller:S,label:e.coalesce(o?.emailLabel,g.$.emailLabel)}),L.Control(P.PasswordInput,{controller:x,label:e.coalesce(o?.passwordLabel,g.$.passwordLabel)}),e.When(c??!1,()=>Y({password:x.signal,rules:w,showLabel:!0})),e.When(r??!1,()=>L.Control(P.PasswordInput,{controller:O,label:e.coalesce(o?.confirmPasswordLabel,g.$.confirmPasswordLabel)})),e.When(l??!1,()=>e.html.div(e.attr.class("bc-auth-form__terms"),e.html.label(e.attr.class("bc-auth-form__checkbox-label"),L.CheckboxInput({value:I.signal.map(k=>k??!1),onChange:k=>I.change(k)}),e.html.span(i||e.coalesce(o?.acceptTermsLabel,g.$.acceptTermsLabel))),e.When(I.errorVisible,()=>e.html.div(e.attr.class("bc-auth-form__field-error"),I.error.map(k=>k||"")))))),C.Button({type:"submit",variant:"filled",color:"primary",loading:h,disabled:v.disabledOrHasErrors},e.attr.class("bc-auth-form__submit"),e.coalesce(o?.signUpButton,g.$.signUpButton))))}function J({onResetPassword:t,labels:o={}}){const n=D(),a=e.prop(!1),c=L.useForm({schema:N,onSubmit:$({task:t,message:"Reset password failed",onStart:()=>{a.set(!0),c.controller.disable()},onEnd:()=>{a.set(!1),c.controller.enable()}}),initialValue:{email:""}}),{controller:s,submit:u}=c;a.on(s.setDisabled);const r=s.field("email");return n.on(l=>{l!=null&&r.change(l)}),e.Use(m.AuthI18n,l=>e.html.form(e.attr.class("bc-auth-form__form"),e.Ensure(s.error,i=>P.Notice({variant:"danger",tone:"prominent",role:"alert"},e.html.div(i))),e.html.p(e.attr.class("bc-auth-form__description"),e.coalesce(o?.resetPasswordDescription,l.$.resetPasswordDescription)),e.on.submit(u),q.Stack(e.attr.class("bc-auth-form__fields"),L.Control(P.EmailInput,{controller:r,label:e.coalesce(o?.emailLabel,l.$.emailLabel)})),C.Button({loading:a,type:"submit",variant:"filled",color:"primary",disabled:s.disabledOrHasErrors},e.attr.class("bc-auth-form__submit"),e.coalesce(o?.resetPasswordButton,l.$.resetPasswordButton))))}function p({provider:t,onClick:o,size:n="md",name:a,icon:c,color:s,flow:u,labels:r}){const l=async()=>{if(o)try{u==="popup"?await o():await o()}catch(i){console.error(`Social login error for ${t} (${u||"redirect"} flow):`,i)}};return C.Button({type:"button",variant:"filled",size:n,color:s,onClick:l,roundedness:"full"},e.attr.class("bc-social-login-button"),e.attr.class(e.computedOf(t)(i=>`bc-social-login-button--${i}`)),e.html.span(e.attr.class("bc-social-login-button__inner"),e.html.span(e.attr.class("bc-social-login-button__icon"),te.Icon({icon:c,size:n},e.attr.class("bc-social-login-button__icon-inner"))),e.Use(m.AuthI18n,i=>e.html.span(e.attr.class("bc-social-login-button__label"),e.bind(e.coalesce(r?.continueWithProvider,i.$.continueWithProvider))(a)))))}function K({providers:t,onProviderClick:o,size:n="md",className:a}){return q.Stack(e.attr.class("bc-social-login-buttons"),e.attr.class(a),e.ForEach(t,c=>p({provider:c.$.provider,flow:c.$.flow,color:c.map(({provider:s})=>d[s].color),name:c.map(({provider:s})=>d[s].name),icon:c.map(({provider:s})=>d[s].icon),onClick:async()=>{o&&await o(c.$.provider.value)},size:n})))}const d={google:{name:"Google",icon:"logos:google-icon",color:"red"},github:{name:"GitHub",icon:"logos:github-icon",color:"black"},apple:{name:"Apple",icon:"logos:apple",color:"stone"},facebook:{name:"Facebook",icon:"logos:facebook",color:"blue"},twitter:{name:"Twitter",icon:"logos:twitter",color:"sky"},x:{name:"X",icon:"logos:x",color:"zinc"},microsoft:{name:"Microsoft",icon:"logos:microsoft-icon",color:"amber"},discord:{name:"Discord",icon:"logos:discord-icon",color:"indigo"},linkedin:{name:"LinkedIn",icon:"logos:linkedin-icon",color:"cyan"},instagram:{name:"Instagram",icon:"logos:instagram-icon",color:"fuchsia"},tiktok:{name:"TikTok",icon:"logos:tiktok-icon",color:"teal"},snapchat:{name:"Snapchat",icon:"simple-icons:snapchat",color:"yellow"},reddit:{name:"Reddit",icon:"logos:reddit-icon",color:"orange"},pinterest:{name:"Pinterest",icon:"logos:pinterest",color:"rose"},twitch:{name:"Twitch",icon:"logos:twitch",color:"purple"},steam:{name:"Steam",icon:"logos:steam",color:"slate"},epic:{name:"Epic Games",icon:"simple-icons:epicgames",color:"neutral"},playstation:{name:"PlayStation",icon:"simple-icons:playstation",color:"violet"},xbox:{name:"Xbox",icon:"simple-icons:xbox",color:"green"},whatsapp:{name:"WhatsApp",icon:"logos:whatsapp-icon",color:"emerald"},wechat:{name:"WeChat",icon:"simple-icons:wechat",color:"lime"},amazon:{name:"Amazon",icon:"simple-icons:amazon",color:"red"},yahoo:{name:"Yahoo",icon:"logos:yahoo",color:"rose"},paypal:{name:"PayPal",icon:"logos:paypal",color:"blue"}},be=t=>p({...t,...d.google,provider:"google"}),Le=t=>p({...t,...d.github,provider:"github"}),_e=t=>p({...t,...d.apple,provider:"apple"}),ke=t=>p({...t,...d.facebook,provider:"facebook"}),ve=t=>p({...t,...d.x,provider:"x"}),Se=t=>p({...t,...d.twitter,provider:"twitter"}),Pe=t=>p({...t,...d.microsoft,provider:"microsoft"}),ye=t=>p({...t,...d.discord,provider:"discord"}),Be=t=>p({...t,...d.linkedin,provider:"linkedin"}),qe=t=>p({...t,...d.instagram,provider:"instagram"}),Ie=t=>p({...t,...d.tiktok,provider:"tiktok"}),xe=t=>p({...t,...d.snapchat,provider:"snapchat"}),Ae=t=>p({...t,...d.reddit,provider:"reddit"}),Ce=t=>p({...t,...d.pinterest,provider:"pinterest"}),Te=t=>p({...t,...d.twitch,provider:"twitch"}),$e=t=>p({...t,...d.steam,provider:"steam"}),Ee=t=>p({...t,...d.epic,provider:"epic"}),Me=t=>p({...t,...d.playstation,provider:"playstation"}),ze=t=>p({...t,...d.xbox,provider:"xbox"}),Re=t=>p({...t,...d.whatsapp,provider:"whatsapp"}),Ue=t=>p({...t,...d.wechat,provider:"wechat"}),Oe=t=>p({...t,...d.amazon,provider:"amazon"}),We=t=>p({...t,...d.yahoo,provider:"yahoo"}),Fe=t=>p({...t,...d.paypal,provider:"paypal"});function W({providers:t,onSocialLogin:o}){return q.Stack(K({providers:t,onProviderClick:o}))}function Q({mode:t,socialProviders:o,initialName:n,initialEmail:a,passwordRules:c,showRememberMe:s,showSocialDivider:u,showPasswordStrength:r,labels:l,onSignIn:i,onSignUp:h,onResetPassword:w,onModeChange:b,onSocialLogin:_,showContainer:v},...U){const B=t!=null?e.Value.deriveProp(t):e.prop("signin");return B.on(S=>b?.(S)),e.Use(m.AuthI18n,S=>{function x(){const g=e.coalesce(l?.hasAccountLink,S.$.hasAccountLink);return e.html.button(e.attr.type("button"),e.attr.class("bc-auth-form__link"),e.on.click(()=>B.set("signin")),g)}function O(){return e.html.button(e.attr.type("button"),e.attr.class("bc-auth-form__link"),e.on.click(()=>B.set("signup")),e.coalesce(l?.noAccountLink,S.$.noAccountLink))}function I(){return e.html.button(e.attr.type("button"),e.attr.class("bc-auth-form__link"),e.on.click(()=>B.set("reset-password")),e.coalesce(l?.forgotPasswordLink,S.$.forgotPasswordLink))}return e.html.div(oe.classes({"bc-auth-container":!0,"bc-auth-container--styled":e.Value.map(v??!0,g=>g)}),e.attr.class(B.map(g=>`bc-auth-container--${g}`)),e.attr.class("bc-auth-form"),e.OneOfValue(B,{signin:()=>e.Fragment(e.html.h2(e.attr.class("bc-auth-form__title"),e.coalesce(l?.signInTitle,S.$.signInTitle)),o!=null?e.Fragment(W({providers:o,onSocialLogin:_}),e.When(u??!1,F)):null,X({onSignIn:i,showRememberMe:s,passwordRules:c,labels:{emailLabel:l?.emailLabel,passwordLabel:l?.passwordLabel,rememberMeLabel:l?.rememberMeLabel,signInButton:l?.signInButton,forgotPasswordLink:l?.forgotPasswordLink,noAccountLink:l?.noAccountLink}}),q.Stack(e.attr.class("bc-auth-form__footer"),O(),I())),signup:()=>e.Fragment(e.html.h2(e.attr.class("bc-auth-form__title"),e.coalesce(l?.signUpTitle,S.$.signUpTitle)),o!=null?e.Fragment(W({providers:o,onSocialLogin:_}),e.When(u??!1,F)):null,Z({labels:{nameLabel:l?.nameLabel,emailLabel:l?.emailLabel,passwordLabel:l?.passwordLabel,confirmPasswordLabel:l?.confirmPasswordLabel,acceptTermsLabel:l?.acceptTermsLabel,signUpButton:l?.signUpButton,hasAccountLink:l?.hasAccountLink},initialEmail:a,initialName:n,onSignUp:h,passwordRules:c,showPasswordStrength:r}),q.Stack(e.attr.class("bc-auth-form__footer"),x())),"reset-password":()=>e.Fragment(e.html.h2(e.attr.class("bc-auth-form__title"),e.coalesce(l?.resetPasswordTitle,S.$.resetPasswordTitle)),J({labels:{backToSignInLink:l?.backToSignInLink,emailLabel:l?.emailLabel,resetPasswordButton:l?.resetPasswordButton,resetPasswordDescription:l?.resetPasswordDescription},onResetPassword:w}),q.Stack(e.attr.class("bc-auth-form__footer"),x()))}),...U)})}function Ve(t){return f.Modal({size:"sm",dismissable:!0,showCloseButton:!0},(o,n)=>t(a=>o({body:Q({showContainer:!1,...a}),header:e.Use(m.AuthI18n,c=>e.coalesce(a.modalTitle,c.$.authenticationTitle))})))}function F({labels:t,className:o}={}){return e.html.div(e.attr.class("bc-auth-divider"),e.attr.class(o),e.html.div(e.attr.class("bc-auth-divider__line")),e.Use(m.AuthI18n,n=>e.html.span(e.attr.class("bc-auth-divider__text"),e.coalesce(t?.text,n.$.orDivider))),e.html.div(e.attr.class("bc-auth-divider__line")))}exports.AmazonLoginButton=Oe;exports.AppleLoginButton=_e;exports.AuthContainer=Q;exports.AuthDivider=F;exports.AuthModal=Ve;exports.DiscordLoginButton=ye;exports.EpicLoginButton=Ee;exports.FacebookLoginButton=ke;exports.GitHubLoginButton=Le;exports.GoogleLoginButton=be;exports.InstagramLoginButton=qe;exports.LinkedInLoginButton=Be;exports.MicrosoftLoginButton=Pe;exports.PasswordStrengthBar=fe;exports.PasswordStrengthIndicator=Y;exports.PasswordStrengthText=we;exports.PayPalLoginButton=Fe;exports.PinterestLoginButton=Ce;exports.PlayStationLoginButton=Me;exports.RedditLoginButton=Ae;exports.ResetPasswordForm=J;exports.SignInForm=X;exports.SignUpForm=Z;exports.SnapchatLoginButton=xe;exports.SocialLoginButton=p;exports.SocialLoginButtons=K;exports.SocialProviders=W;exports.SteamLoginButton=$e;exports.TiktokLoginButton=Ie;exports.TwitchLoginButton=Te;exports.TwitterLoginButton=Se;exports.WeChatLoginButton=Ue;exports.WhatsAppLoginButton=Re;exports.XLoginButtin=ve;exports.XboxLoginButton=ze;exports.YahooLoginButton=We;exports.authSchemas=pe;exports.calculatePasswordStrength=R;exports.createEmailSchema=A;exports.createPasswordSchema=E;exports.createSignInSchema=M;exports.createSignUpSchema=z;exports.createSocialLoginUrl=ie;exports.defaultPasswordRules=y;exports.defaultSignInSchema=me;exports.defaultSignUpSchema=de;exports.emailSchema=V;exports.formatAuthError=le;exports.formatProviderName=j;exports.formatSocialLoginText=re;exports.generateRandomString=H;exports.getProviderColor=ne;exports.getProviderIcon=ae;exports.isBrowser=ue;exports.isValidEmail=se;exports.openSocialLoginPopup=ce;exports.providerInfo=T;exports.requestToControllerValidation=$;exports.resetPasswordSchema=N;exports.socialProviderInfo=d;exports.useAuthEmailProp=D;exports.validateEmail=he;exports.validatePassword=ge;
|