Files
RDO/dist/assets/js/Auth-KZISTjMo.js
2026-02-20 07:25:32 -03:00

2 lines
19 KiB
JavaScript

import{j as e}from"./query-vendor-BLVqILA6.js";import{r as h,d as P,u as S}from"./router-vendor-D4by-_6Z.js";import{s as j,u as y}from"./index-doec96Hx.js";import{N as $}from"./NeuralNetworkBackground-CER-dIFD.js";import"./react-vendor-CqRd3GwO.js";import"./ui-vendor-CyRvbSfR.js";import"./supabase-vendor-CnnNSQLo.js";import"./state-vendor-DHadhBU5.js";const M=()=>{const[n,l]=h.useState(!1),[m,i]=h.useState(null),d=async o=>{try{l(!0),i(null);const{data:s,error:t}=await j.auth.signInWithOAuth({provider:o,options:{redirectTo:`${window.location.origin}/auth/callback`,queryParams:{access_type:"offline",prompt:"consent"}}});if(t)throw t;return{data:s,error:null}}catch(s){const t=s instanceof Error?s.message:"Erro ao fazer login";return i({message:t,provider:o}),{data:null,error:t}}finally{l(!1)}};return{loading:n,error:m,signInWithGoogle:()=>d("google"),signInWithMicrosoft:()=>d("azure"),signInWithProvider:d,linkProvider:async o=>{try{l(!0),i(null);const{data:s,error:t}=await j.auth.linkIdentity({provider:o});if(t)throw t;return{data:s,error:null}}catch(s){const t=s instanceof Error?s.message:"Erro ao vincular conta";return i({message:t,provider:o}),{data:null,error:t}}finally{l(!1)}},unlinkProvider:async o=>{try{l(!0),i(null);const{data:{user:s}}=await j.auth.getUser();if(!s)throw new Error("Usuário não autenticado");const t=s.identities?.find(v=>v.provider===o);if(!t)throw new Error(`Conta ${o} não vinculada`);const{data:u,error:g}=await j.auth.unlinkIdentity(t);if(g)throw g;return{data:u,error:null}}catch(s){const t=s instanceof Error?s.message:"Erro ao desvincular conta";return i({message:t,provider:o}),{data:null,error:t}}finally{l(!1)}},hasProvider:async o=>{const{data:{user:s}}=await j.auth.getUser();return s?.identities?.some(t=>t.provider===o)??!1}}},F=({mode:n="login",onSuccess:l,onError:m})=>{const{loading:i,signInWithGoogle:d,signInWithMicrosoft:x,linkProvider:r}=M(),f=async()=>{const{error:o}=n==="login"?await d():await r("google");o?m?.(o):l?.()},c=async()=>{const{error:o}=n==="login"?await x():await r("azure");o?m?.(o):l?.()},b=n==="login"?"Entrar com":"Vincular";return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{onClick:f,disabled:i,className:"w-full flex items-center justify-center gap-3 px-4 py-3 bg-white border-2 border-gray-300 rounded-lg hover:bg-gray-50 hover:border-gray-400 transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed group",children:[e.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[e.jsx("path",{fill:"#4285F4",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"}),e.jsx("path",{fill:"#34A853",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"}),e.jsx("path",{fill:"#FBBC05",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"}),e.jsx("path",{fill:"#EA4335",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"})]}),e.jsxs("span",{className:"font-medium text-gray-700",children:[b," Google"]})]}),e.jsxs("button",{onClick:c,disabled:i,className:"w-full flex items-center justify-center gap-3 px-4 py-3 bg-white border-2 border-gray-300 rounded-lg hover:bg-gray-50 hover:border-gray-400 transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 23 23",children:[e.jsx("path",{fill:"#f3f3f3",d:"M0 0h23v23H0z"}),e.jsx("path",{fill:"#f35325",d:"M1 1h10v10H1z"}),e.jsx("path",{fill:"#81bc06",d:"M12 1h10v10H12z"}),e.jsx("path",{fill:"#05a6f0",d:"M1 12h10v10H1z"}),e.jsx("path",{fill:"#ffba08",d:"M12 12h10v10H12z"})]}),e.jsxs("span",{className:"font-medium text-gray-700",children:[b," Microsoft"]})]}),n==="login"&&e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("div",{className:"w-full border-t border-gray-300"})}),e.jsx("div",{className:"relative flex justify-center text-sm",children:e.jsx("span",{className:"px-2 bg-white text-gray-500",children:"ou"})})]})]})},z=({onSuccess:n,onSwitchToRegister:l})=>{const{login:m,loading:i,error:d,clearError:x}=y(),[r,f]=h.useState({email:"",password:""}),[c,b]=h.useState(!1),o=async t=>{if(t.preventDefault(),x(),!r.email||!r.password)return;(await m(r)).success&&n&&n()},s=t=>{const{name:u,value:g}=t.target;f(v=>({...v,[u]:g}))};return e.jsx("div",{className:"w-full max-w-md mx-auto",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("h2",{className:"text-2xl font-bold text-white mb-2",children:"Entrar"}),e.jsx("p",{className:"text-blue-200",children:"Acesse sua conta"})]}),d&&e.jsx("div",{className:"mb-4 p-3 bg-red-500/20 border border-red-400/30 rounded-xl backdrop-blur-sm",children:e.jsx("p",{className:"text-red-200 text-sm",children:d})}),e.jsx(F,{mode:"login",onSuccess:n,onError:t=>{}}),e.jsxs("form",{onSubmit:o,className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium text-white mb-2",children:"Email"}),e.jsx("input",{type:"email",id:"email",name:"email",value:r.email,onChange:s,required:!0,className:"w-full px-4 py-3 bg-white/10 border border-white/20 rounded-xl text-white placeholder-blue-200 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:border-transparent backdrop-blur-sm transition-all duration-200",placeholder:"seu@email.com"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"password",className:"block text-sm font-medium text-white mb-2",children:"Senha"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:c?"text":"password",id:"password",name:"password",value:r.password,onChange:s,required:!0,className:"w-full px-4 py-3 bg-white/10 border border-white/20 rounded-xl text-white placeholder-blue-200 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:border-transparent backdrop-blur-sm transition-all duration-200 pr-12",placeholder:"Sua senha"}),e.jsx("button",{type:"button",onClick:()=>b(!c),className:"absolute inset-y-0 right-0 pr-4 flex items-center text-blue-200 hover:text-white transition-colors duration-200",children:c?"🙈":"👁️"})]})]}),e.jsx("button",{type:"submit",disabled:i||!r.email||!r.password,className:"w-full bg-gradient-to-r from-blue-500 to-purple-600 text-white py-3 px-6 rounded-xl hover:from-blue-600 hover:to-purple-700 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed transition-all duration-200 shadow-lg hover:shadow-xl font-semibold",children:i?e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"}),"Entrando..."]}):"Entrar"})]}),e.jsx("div",{className:"mt-6 text-center",children:e.jsx("button",{type:"button",className:"text-blue-300 hover:text-white text-sm font-medium transition-colors duration-200",onClick:()=>{alert("Funcionalidade de recuperação de senha será implementada em breve")},children:"Esqueceu sua senha?"})}),l&&e.jsx("div",{className:"mt-4 text-center",children:e.jsxs("p",{className:"text-blue-200 text-sm",children:["Não tem uma conta?"," ",e.jsx("button",{type:"button",onClick:l,className:"text-blue-300 hover:text-white font-medium transition-colors duration-200",children:"Cadastre-se"})]})})]})})},D=({onSuccess:n,onSwitchToLogin:l})=>{const{register:m,loading:i,error:d,clearError:x}=y(),[r,f]=h.useState({nome:"",email:"",password:"",confirmPassword:"",cpf:"",telefone:""}),[c,b]=h.useState(!1),[o,s]=h.useState(!1),[t,u]=h.useState({}),g=()=>{const a={};return r.nome.trim()||(a.nome="Nome é obrigatório"),r.email.trim()?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r.email)||(a.email="Email inválido"):a.email="Email é obrigatório",r.password?r.password.length<6&&(a.password="Senha deve ter pelo menos 6 caracteres"):a.password="Senha é obrigatória",r.password!==r.confirmPassword&&(a.confirmPassword="Senhas não coincidem"),r.cpf&&!/^\d{11}$/.test(r.cpf.replace(/\D/g,""))&&(a.cpf="CPF deve ter 11 dígitos"),r.telefone&&!/^\d{10,11}$/.test(r.telefone.replace(/\D/g,""))&&(a.telefone="Telefone deve ter 10 ou 11 dígitos"),u(a),Object.keys(a).length===0},v=async a=>{if(a.preventDefault(),x(),u({}),!g())return;(await m({nome:r.nome,email:r.email,password:r.password,cpf:r.cpf||void 0,telefone:r.telefone||void 0})).success&&(alert("Cadastro realizado com sucesso! Verifique seu email para confirmar a conta."),n&&n())},w=a=>{const{name:p,value:E}=a.target;f(N=>({...N,[p]:E})),t[p]&&u(N=>({...N,[p]:""}))},k=a=>a.replace(/\D/g,"").replace(/(\d{3})(\d{3})(\d{3})(\d{2})/,"$1.$2.$3-$4"),C=a=>{const p=a.replace(/\D/g,"");return p.length<=10?p.replace(/(\d{2})(\d{4})(\d{4})/,"($1) $2-$3"):p.replace(/(\d{2})(\d{5})(\d{4})/,"($1) $2-$3")};return e.jsx("div",{className:"w-full max-w-md mx-auto",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("h2",{className:"text-2xl font-bold text-white mb-2",children:"Cadastrar"}),e.jsx("p",{className:"text-blue-200",children:"Crie sua conta"})]}),d&&e.jsx("div",{className:"mb-4 p-3 bg-red-500/20 border border-red-400/30 rounded-xl backdrop-blur-sm",children:e.jsx("p",{className:"text-red-200 text-sm",children:d})}),e.jsxs("form",{onSubmit:v,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"nome",className:"block text-sm font-medium text-white mb-2",children:"Nome Completo *"}),e.jsx("input",{type:"text",id:"nome",name:"nome",value:r.nome,onChange:w,required:!0,className:`w-full px-4 py-3 bg-white/10 border rounded-xl text-white placeholder-blue-200 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:border-transparent backdrop-blur-sm transition-all duration-200 ${t.nome?"border-red-400/50":"border-white/20"}`,placeholder:"Seu nome completo"}),t.nome&&e.jsx("p",{className:"text-red-300 text-xs mt-1",children:t.nome})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium text-white mb-2",children:"Email *"}),e.jsx("input",{type:"email",id:"email",name:"email",value:r.email,onChange:w,required:!0,className:`w-full px-4 py-3 bg-white/10 border rounded-xl text-white placeholder-blue-200 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:border-transparent backdrop-blur-sm transition-all duration-200 ${t.email?"border-red-400/50":"border-white/20"}`,placeholder:"seu@email.com"}),t.email&&e.jsx("p",{className:"text-red-300 text-xs mt-1",children:t.email})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"cpf",className:"block text-sm font-medium text-white mb-2",children:"CPF"}),e.jsx("input",{type:"text",id:"cpf",name:"cpf",value:k(r.cpf),onChange:a=>w({...a,target:{...a.target,value:a.target.value.replace(/\D/g,"")}}),maxLength:14,className:`w-full px-4 py-3 bg-white/10 border rounded-xl text-white placeholder-blue-200 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:border-transparent backdrop-blur-sm transition-all duration-200 ${t.cpf?"border-red-400/50":"border-white/20"}`,placeholder:"000.000.000-00"}),t.cpf&&e.jsx("p",{className:"text-red-300 text-xs mt-1",children:t.cpf})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"telefone",className:"block text-sm font-medium text-white mb-2",children:"Telefone"}),e.jsx("input",{type:"text",id:"telefone",name:"telefone",value:C(r.telefone),onChange:a=>w({...a,target:{...a.target,value:a.target.value.replace(/\D/g,"")}}),maxLength:15,className:`w-full px-4 py-3 bg-white/10 border rounded-xl text-white placeholder-blue-200 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:border-transparent backdrop-blur-sm transition-all duration-200 ${t.telefone?"border-red-400/50":"border-white/20"}`,placeholder:"(11) 99999-9999"}),t.telefone&&e.jsx("p",{className:"text-red-300 text-xs mt-1",children:t.telefone})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"password",className:"block text-sm font-medium text-white mb-2",children:"Senha *"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:c?"text":"password",id:"password",name:"password",value:r.password,onChange:w,required:!0,className:`w-full px-4 py-3 bg-white/10 border rounded-xl text-white placeholder-blue-200 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:border-transparent backdrop-blur-sm transition-all duration-200 pr-10 ${t.password?"border-red-400/50":"border-white/20"}`,placeholder:"Mínimo 6 caracteres"}),e.jsx("button",{type:"button",onClick:()=>b(!c),className:"absolute inset-y-0 right-0 pr-3 flex items-center text-blue-200 hover:text-white",children:c?"🙈":"👁️"})]}),t.password&&e.jsx("p",{className:"text-red-300 text-xs mt-1",children:t.password})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"confirmPassword",className:"block text-sm font-medium text-white mb-2",children:"Confirmar Senha *"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:o?"text":"password",id:"confirmPassword",name:"confirmPassword",value:r.confirmPassword,onChange:w,required:!0,className:`w-full px-4 py-3 bg-white/10 border rounded-xl text-white placeholder-blue-200 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:border-transparent backdrop-blur-sm transition-all duration-200 pr-10 ${t.confirmPassword?"border-red-400/50":"border-white/20"}`,placeholder:"Confirme sua senha"}),e.jsx("button",{type:"button",onClick:()=>s(!o),className:"absolute inset-y-0 right-0 pr-3 flex items-center text-blue-200 hover:text-white",children:o?"🙈":"👁️"})]}),t.confirmPassword&&e.jsx("p",{className:"text-red-300 text-xs mt-1",children:t.confirmPassword})]}),e.jsx("button",{type:"submit",disabled:i,className:"w-full bg-gradient-to-r from-blue-500 to-purple-600 text-white py-3 px-4 rounded-xl hover:from-blue-600 hover:to-purple-700 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:ring-offset-2 focus:ring-offset-transparent disabled:opacity-50 disabled:cursor-not-allowed transition-all duration-200 font-medium backdrop-blur-sm",children:i?e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"}),"Cadastrando..."]}):"Cadastrar"})]}),l&&e.jsx("div",{className:"mt-4 text-center",children:e.jsxs("p",{className:"text-blue-200 text-sm",children:["Já tem uma conta?"," ",e.jsx("button",{type:"button",onClick:l,className:"text-white hover:text-blue-200 font-medium underline transition-colors duration-200",children:"Entrar"})]})})]})})},L="/assets/png/tracksteel-logo-CJR9ckUT.png",R=()=>{const n=P(),l=S(),{isAuthenticated:m,loading:i,bypassLogin:d}=y(),[x,r]=h.useState("login");h.useEffect(()=>{if(m&&!i){const s=l.state?.from?.pathname||"/dashboard";n(s,{replace:!0})}},[m,i,n,l]),h.useEffect(()=>{const s=l.pathname;s.includes("register")||s.includes("cadastro")?r("register"):r("login")},[l.pathname]);const f=()=>{const s=l.state?.from?.pathname||"/dashboard";n(s,{replace:!0})},c=async()=>{try{if((await d()).success){const t=l.state?.from?.pathname||"/dashboard";n(t,{replace:!0})}}catch{}},b=()=>{r("login"),n("/login",{replace:!0})},o=()=>{r("register"),n("/register",{replace:!0})};return i?e.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto mb-4"}),e.jsx("p",{className:"text-gray-600",children:"Carregando..."})]})}):e.jsxs("div",{className:"min-h-screen relative flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8 overflow-hidden",children:[e.jsx($,{}),e.jsxs("div",{className:"relative z-10 max-w-md w-full space-y-8 animate-fade-in",children:[e.jsx("div",{className:"text-center",children:e.jsxs("div",{className:"mx-auto mb-6",children:[e.jsx("div",{className:"bg-white/10 backdrop-blur-md rounded-xl shadow-lg border border-white/20 p-6 mb-4 inline-block",children:e.jsxs("div",{className:"w-40 h-30 flex items-center justify-center",children:[e.jsx("img",{src:L,alt:"TrackSteel Logo",width:"160",height:"120",className:"mx-auto drop-shadow-2xl",onLoad:()=>{},onError:s=>{const t=s.target;t.style.display="none";const u=t.nextElementSibling;u&&(u.style.display="block")}}),e.jsx("div",{className:"hidden text-white text-center",style:{display:"none"},children:e.jsxs("svg",{className:"w-40 h-30 mx-auto mb-2",viewBox:"0 0 160 120",fill:"none",children:[e.jsx("rect",{width:"160",height:"120",rx:"8",fill:"rgba(255,255,255,0.1)",stroke:"rgba(255,255,255,0.3)"}),e.jsx("text",{x:"80",y:"65",textAnchor:"middle",className:"fill-white text-lg font-bold",children:"LOGO"})]})})]})}),e.jsx("div",{className:"mt-4",children:e.jsx("div",{className:"h-px bg-gradient-to-r from-transparent via-blue-300 to-transparent w-32 mx-auto"})})]})}),e.jsxs("div",{className:"flex bg-white/10 backdrop-blur-sm border border-white/20 rounded-xl p-1 mb-6",children:[e.jsx("button",{onClick:()=>r("login"),className:`flex-1 py-3 px-4 rounded-lg text-sm font-semibold transition-all duration-200 ${x==="login"?"bg-white/20 text-white shadow-lg":"text-blue-200 hover:text-white hover:bg-white/10"}`,children:"Entrar"}),e.jsx("button",{onClick:()=>r("register"),className:`flex-1 py-3 px-4 rounded-lg text-sm font-semibold transition-all duration-200 ${x==="register"?"bg-white/20 text-white shadow-lg":"text-blue-200 hover:text-white hover:bg-white/10"}`,children:"Cadastrar"})]}),e.jsx("div",{className:"mb-6",children:e.jsxs("div",{className:"bg-yellow-500/20 border border-yellow-400/30 rounded-xl backdrop-blur-sm p-4",children:[e.jsxs("div",{className:"flex items-center mb-2",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-yellow-300",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),e.jsx("div",{className:"ml-3",children:e.jsx("h3",{className:"text-sm font-semibold text-yellow-200",children:"Modo Desenvolvimento"})})]}),e.jsxs("div",{className:"ml-8",children:[e.jsx("p",{className:"text-sm text-yellow-100 mb-3",children:"Botão temporário para acesso direto ao sistema sem autenticação."}),e.jsx("button",{onClick:c,className:"bg-yellow-300/90 hover:bg-yellow-200 text-yellow-900 font-medium py-2 px-4 rounded-lg text-sm transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-yellow-400 focus:ring-offset-2 shadow-lg hover:shadow-xl",children:"🚧 Entrar sem Login (DEV)"})]})]})}),e.jsx("div",{className:"bg-white/10 backdrop-blur-md rounded-2xl shadow-2xl border border-white/20 p-8 transition-all duration-300 hover:bg-white/15 animate-slide-up",children:x==="login"?e.jsx(z,{onSuccess:f,onSwitchToRegister:o}):e.jsx(D,{onSuccess:f,onSwitchToLogin:b})}),e.jsx("div",{className:"text-center text-sm text-gray-300",children:e.jsx("p",{className:"italic",children:"Desenvolvido por TrackSteel"})})]})]})};export{R as default};