PageSourceSearch

https://padeltrainer.ai/assets/Auth-Bp3GdxeV.js

js padeltrainer.ai collected 2026-10-05 12:45:24 UTC 9,274 bytes, 1 lines download raw bytes

1import{j as r}from"./vendor-query-DCZXcvLJ.js";import{f as q,r as c,e as K,L as b}from"./vendor-react-DWpktzy-.js";import{z as $,R as V,Q as F,D as l,bD as v,bE as E,a8 as W,bs as Y,b as J,k as Q,s as X,aT as Z,a3 as ee,c as re,m as L,K as T,I as _,bF as te,bG as ie,bH as se,bI as ae,bJ as ne,an as B,t as D,bK as oe}from"./index-BY5tr4Tp.js";import{u as ce}from"./vendor-i18n-B9VkIq3M.js";import"./vendor-ui-xXmBVFTK.js";import"./vendor-styling--BulIq_u.js";import"./vendor-supabase-Iia0ULwR.js";import"./vendor-zod-bhLDXFPS.js";function ve(){const[d]=q(),[y,f]=c.useState(!1),[R,I]=c.useState(!1),[S,M]=c.useState(""),[N,U]=c.useState(""),{toast:s}=$(),a=K(),{user:x,role:g,loading:w,profileReady:k,profileFetchFailed:A,refreshAuth:C,isAcademyManager:O,isClubManager:z}=V(),{t:e}=ce("auth");c.useEffect(()=>{const t=new URLSearchParams(window.location.hash.substring(1)),i=t.get("access_token"),n=t.get("refresh_token"),o=t.get("provider_token");i&&n&&!o&&(I(!0),F.auth.setSession({access_token:i,refresh_token:n}).then(({error:m})=>{m&&(l.error("Failed to set session from magic link",m,{component:"Auth",action:"magic_link"}),s({title:e("signIn.error","Login failed"),description:e("verification.linkExpired","The login link may have expired. Please try again."),variant:"destructive"})),window.history.replaceState(null,"",window.location.pathname),I(!1)}).catch(()=>{I(!1)}))},[s,e]),c.useEffect(()=>{const t=v(d.get("redirect"));t&&sessionStorage.setItem("redirectAfterLogin",t)},[d]),c.useEffect(()=>{const t=d.get("type"),i=d.get("error"),n=d.get("error_description");i?s({title:e("verification.error","Verification Error"),description:n||e("verification.linkExpired","This verification link has expired or was already used."),variant:"destructive"}):(t==="signup"||t==="email_change")&&s({title:e("verification.confirmed"),description:e("verification.confirmedDescription")})},[d,s,e]);const P=v(d.get("redirect")),u=c.useRef(!1);c.useEffect(()=>{if(!w&&x&&!R&&k){const t=sessionStorage.getItem("redirectAfterLogin"),i=v(t);if(t&&!i&&sessionStorage.removeItem("redirectAfterLogin"),A&&!g){s({title:e("signIn.error","Error"),description:e("signIn.fetchFailed","Could not load your account data. Please try again."),variant:"destructive"}),u.current=!1;return}if(g){localStorage.removeItem("pendingRole");const n=v(localStorage.getItem(E));i?(sessionStorage.removeItem("redirectAfterLogin"),a(i)):n?(localStorage.removeItem(E),a(n)):(async()=>{if(O)a("/app/academy");else if(g==="admin")a("/app/admin");else if(g==="trainer")try{const m=await te(x.id);a(m?"/app/trainer":"/app/onboarding/trainer")}catch{a("/app/onboarding/trainer")}else a(g==="club"||z?"/app/club":g==="academy"?"/app/academy/onboarding":"/app/player")})()}else u.current||(u.current=!0,(async()=>{try{const{data:o,error:m}=await F.from("user_roles").select("role").eq("user_id",x.id).limit(1);if(m){l.error("Role check query failed",m,{component:"Auth"}),s({title:e("signIn.error","Error"),description:e("signIn.fetchFailed","Could not load your account data. Please try again."),variant:"destructive"}),u.current=!1;return}if(o&&o.length>0)localStorage.removeItem("pendingRole"),await C();else{if(i){sessionStorage.removeItem("redirectAfterLogin");const h=v(i);h&&localStorage.setItem(E,h)}const p=localStorage.getItem("pendingRole");if(p&&ie(p)){const{success:h,error:j}=await se(p);if(!h||j){l.error("OAuth signup completion failed",j??new Error("Unknown"),{component:"Auth",pendingRole:p}),s({title:e("signIn.error","Error"),description:j?.message||e("signIn.oauthSignupFailed","Could not finish setting up your account. Please try again or use email signup."),variant:"destructive"}),u.current=!1;return}localStorage.removeItem("pendingRole"),sessionStorage.removeItem("pendingRole"),await C(),a(ae(p))}else if(p)localStorage.removeItem("pendingRole"),sessionStorage.removeItem("pendingRole"),l.warn("Invalid pendingRole after OAuth",{component:"Auth",pendingRole:p}),s({title:e("signIn.error","Error"),description:e("signIn.oauthSignupFailed","Could not finish setting up your account. Please try again or use email signup."),variant:"destructive"}),u.current=!1;else{s({title:e("signIn.error","Error"),description:e("signIn.noRoleAssigned","Your account has no role yet. Choose how you want to use PadelTrainer."),variant:"destructive"});const h=i?`/app/signup?redirect=${encodeURIComponent(i)}`:"/app/signup";a(h)}}}catch(o){l.error("Role check failed",o,{component:"Auth"}),s({title:e("signIn.error","Error"),description:e("signIn.fetchFailed","Could not load your account data. Please try again."),variant:"destructive"}),u.current=!1}})())}},[x,g,w,k,A,a]);const G=async t=>{t.preventDefault(),f(!0);try{const{error:i}=await ne(S,N);
1if(i){l.error("Sign in failed",i,{component:"Auth",action:"signIn"});const n=(i.message||i.msg||"").toLowerCase(),o=n.includes("invalid login")||n.includes("invalid credentials")?e("signIn.invalidCredentials","E-mailadres of wachtwoord is onjuist."):n.includes("email not confirmed")?e("signIn.emailNotConfirmed","Bevestig eerst je e-mailadres via de link in je inbox."):B(i,e("signIn.genericError","Er ging iets mis. Probeer het opnieuw."));s({title:e("signIn.error","Error"),description:o,variant:"destructive"})}else try{D("login",{method:"email"})}catch{}}catch(i){l.error("Unexpected sign in error",i,{component:"Auth"}),s({title:e("signIn.error","Error"),description:e("signIn.genericError","Something went wrong. Please try again."),variant:"destructive"})}finally{f(!1)}},H=async()=>{f(!0);try{try{D("login",{method:"google"})}catch{}const{error:t}=await oe();t&&(s({title:e("signIn.error","Error"),description:B(t,e("signIn.genericError","Er ging iets mis. Probeer het opnieuw.")),variant:"destructive"}),f(!1))}catch(t){l.error("Unexpected Google sign in error",t,{component:"Auth"}),f(!1)}};return w||R?r.jsx(W,{}):r.jsx(Y,{featureName:"Auth",onRetry:()=>window.location.reload(),children:r.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4","data-testid":"page-auth",children:r.jsxs(J,{className:"w-full max-w-md","data-testid":"form-login",children:[r.jsxs(Q,{className:"text-center",children:[r.jsxs("div",{className:"flex items-center justify-between mb-4",children:[r.jsxs(b,{to:"/",className:"inline-flex items-center gap-2 text-sm text-muted-foreground hover:text-primary",children:[r.jsx(X,{className:"h-4 w-4"}),e("backToHome","Back to home")]}),r.jsx(Z,{})]}),r.jsx("div",{className:"mb-4",children:r.jsxs("span",{className:"font-bold text-2xl",children:["PadelTrainer",r.jsx("span",{className:"text-primary",children:".ai"})]})}),r.jsx(ee,{children:e("subtitle")})]}),r.jsxs(re,{className:"space-y-4",children:[r.jsxs(L,{variant:"outline",className:"w-full h-12 text-base",onClick:H,disabled:y,"data-testid":"auth-google-button",children:[r.jsxs("svg",{className:"mr-2 h-5 w-5",viewBox:"0 0 24 24",children:[r.jsx("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z",fill:"#4285F4"}),r.jsx("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),r.jsx("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),r.jsx("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]}),e("social.google")]}),r.jsxs("div",{className:"relative",children:[r.jsx("div",{className:"absolute inset-0 flex items-center",children:r.jsx("span",{className:"w-full border-t"})}),r.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:r.jsx("span",{className:"bg-card px-2 text-muted-foreground",children:e("social.orEmail","or with email")})})]}),r.jsxs("form",{onSubmit:G,className:"space-y-4",children:[r.jsxs("div",{className:"space-y-2",children:[r.jsx(T,{htmlFor:"signin-email",children:e("form.email")}),r.jsx(_,{id:"signin-email",type:"email",placeholder:e("form.emailPlaceholder"),value:S,onChange:t=>M(t.target.value),required:!0,"data-testid":"auth-email-input"})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx(T,{htmlFor:"signin-password",children:e("form.password")}),r.jsx(b,{to:"/app/forgot-password",className:"text-sm text-primary hover:underline",children:e("signIn.forgotPassword","Forgot password?")})]}),r.jsx(_,{id:"signin-password",type:"password",placeholder:e("form.passwordPlaceholder"),value:N,onChange:t=>U(t.target.value),required:!0,"data-testid":"auth-password-input"})]}),r.jsx(L,{type:"submit",className:"w-full",disabled:y,"data-testid":"auth-login-button",children:e(y?"signIn.loading":"signIn.button")})]}),r.jsx("div",{className:"pt-4 border-t text-center",children:r.jsxs("p",{className:"text-sm text-muted-foreground",children:[e("signIn.noAccount","Don't have an account?")," ",r.jsx(b,{to:`/app/signup${P?`?redirect=${encodeURIComponent(P)}`:""}`,className:"font-medium text-primary hover:underline",children:e("signupPicker.signUp","Sign up")})]})})]})]})})})}export{ve 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.