js • Lines: 2"use strict";(self.webpackChunknew_site=self.webpackChunknew_site||[]).push([[584],{7584(e,a,t){t.r(a),t.d(a,{default:()=>j});var s=t(5544),n=t(5043),i=t(5016),r=t(6322),l=t(3604),o=t(791),c=t(1719),d=t(4282),u=t(8628),h=t(3519),m=t(8770),g=t(7994),p=t(7417),x=t(6058),w=t(184),y=t(1800),b=t(579);const A=e=>{const a={"auth/user-not-found":"No account found with this email.","auth/wrong-password":"Incorrect password. Try again.","auth/invalid-credential":"Invalid email or password.","auth/email-already-in-use":"An account with this email already exists.","auth/weak-password":"Password must be at least 6 characters.","auth/invalid-email":"Please enter a valid email address.","auth/too-many-requests":"Too many attempts. Please wait a moment and try again.","auth/popup-closed-by-user":"Sign-in popup was closed before completing.","auth/popup-blocked":"Popup was blocked by your browser. Allow popups for this site.","auth/cancelled-popup-request":"Sign-in cancelled.","auth/account-exists-with-different-credential":"An account already exists with this email using a different sign-in method.","auth/requires-recent-login":"Please log out and log back in to perform this action.","auth/network-request-failed":"Network error. Check your internet connection.","auth/operation-not-allowed":"This sign-in method is not enabled. Contact the site owner.","auth/user-disabled":"This account has been disabled.","auth/unauthorized-domain":"This domain is not authorized for sign-in."};return a[null!==e&&void 0!==e&&e.startsWith("auth/")?e:"auth/".concat(e)]||a[e]||"Something went wrong (".concat(e,"). Please try again.")},f=/^[a-zA-Z0-9_-]+$/;function j(){const e=(0,i.A)(),a=e.signInWithGoogle,t=e.signUpWithEmail,j=e.signInWithEmail,v=e.refreshProfile,k=(0,r.Zp)(),N=(0,r.ok)(),S=(0,s.A)(N,1)[0],C=(S.get("redirect")||"/contents/scores")+(S.get("like")?"?like=1":""),T=(0,n.useState)(""),P=(0,s.A)(T,2),q=P[0],z=P[1],E=(0,n.useState)(""),I=(0,s.A)(E,2),U=I[0],G=I[1],H=(0,n.useState)(""),L=(0,s.A)(H,2),W=L[0],B=L[1],D=(0,n.useState)(null),_=(0,s.A)(D,2),Z=_[0],F=_[1],V=(0,n.useState)(!1),$=(0,s.A)(V,2),J=$[0],K=$[1],M=(0,n.useState)(!1),O=(0,s.A)(M,2),Q=O[0],R=O[1],X=(0,n.useState)(""),Y=(0,s.A)(X,2),ee=Y[0],ae=Y[1],te=(0,n.useState)(!1),se=(0,s.A)(te,2),ne=se[0],ie=se[1],re=(0,n.useState)(!1),le=(0,s.A)(re,2),oe=le[0],ce=le[1],de=(0,n.useCallback)(async e=>{!e||e.length<3?F(null):(K(!0),F(await async function(e){return!e||e.length<3?null:!(await(0,l.x7)((0,l.H9)(o.db,(0,y.n)("usernames"),e.toLowerCase()))).exists()}(e)),K(!1))},[]);(0,n.useEffect)(()=>{const e=setTimeout(()=>de(W),400);return()=>clearTimeout(e)},[W,de]);const ue=()=>W&&Q?W.length<3?"At least 3 characters.":W.length>20?"At most 20 characters.":f.test(W)?!1===Z?"Username taken.":"":"Letters, numbers, underscores, hyphens only.":"",he=async e=>{for(let t=0;t<10;t++){const t=await(0,l.x7)((0,l.H9)(o.db,(0,y.n)("profiles"),e));var a;if(t.exists())return void(null!==(a=t.data())&&void 0!==a&&a.username?k(C):k("/setup-username"));await new Promise(e=>setTimeout(e,300))}k("/")};return(0,b.jsx)(h.A,{className:"d-flex justify-content-center mt-5",children:(0,b.jsx)(u.A,{bg:"dark",text:"light",style:{width:"420px"},children:(0,b.jsxs)(u.A.Body,{children:[(0,b.jsxs)(u.A.Title,{className:"text-center mb-4",children:[(0,b.jsx)(w.maD,{className:"me-2"}),Q?"Sign Up":"Sign In"]}),ee&&(0,b.jsx)(c.A,{variant:"danger",className:"py-2 small",children:ee}),oe&&(0,b.jsx)(c.A,{variant:"info",className:"py-2 small",children:"Verification email sent. Please check your inbox before signing in."}),(0,b.jsxs)(m.A,{onSubmit:async e=>{e.preventDefault(),ae(""),ce(!1),ie(!0);try{if(Q){const e=ue();if(e||!0!==Z)throw new Error(e||"Choose a different username.");const a=await t(q,U);await(0,l.BN)((0,l.H9)(o.db,(0,y.n)("usernames"),W.toLowerCase()),{uid:a.user.uid}),await(0,l.BN)((0,l.H9)(o.db,(0,y.n)("profiles"),a.user.uid),{username:W.toLowerCase()},{merge:!0}),await v(),ce(!0)}else{const e=await j(q,U);await he(e.user.uid)}}catch(e){ae(A(e.code)||e.message)}finally{ie(!1)}},children:[Q&&(0,b.jsxs)(m.A.Group,{className:"mb-2",children:[(0,b.jsxs)(g.A,{children:[(0,b.jsx)(g.A.Text,{className:"bg-black text-secondary border-secondary",children:"@"}),(0,b.jsx)(m.A.Control,{type:"text",placeholder:"Username",value:W,onChange:e=>{B(e.target.value),F(null)},required:!0,className:"bg-dark text-light border-secondary",autoComplete:"off",spellCheck:!1})]}),W.length>=3&&(0,b.jsx)(m.A.Text,{className:!0===Z?"text-success":!1===Z?"text-danger":"text-secondary",children:J?(0,b.jsx)(p.A,{animation:"border",size:"sm"}):!0===Z?"\u2713 Available":!1===Z?"\u2717 Taken":""}),ue()&&!1!==Z&&(0,b.jsx)(m.A.Text,{className:"text-danger d-block",children:ue()})]}),(0,b.jsx)(m.A.Group,{className:"mb-2",children:(0,b.jsx)(m.A.Control,{type:"email",placeholder:"Email",value:q,onChange:e=>z(e.target.value),required:!0,className:"bg-dark text-light border-secondary"})}),(0,b.jsx)(m.A.Group,{className:"mb-3",children:(0,b.jsx)(m.A.Control,{type:"password",placeholder:"Password",value:U,onChange:e=>G(e.target.value),required:!0,minLength:6,className:"bg-dark text-light border-secondary"})}),(0,b.jsx)(d.A,{type:"submit",variant:"primary",className:"w-100",disabled:ne,children:ne?(0,b.jsx)(p.A,{size:"sm"}):Q?"Sign Up with Email":"Sign In with Email"})]}),(0,b.jsx)("div",{className:"text-center mt-3",children:(0,b.jsx)("small",{className:"text-secondary",style:{fontSize:"11px",lineHeight:1.4},children:"We only store your email, username, and avatar for authentication and display purposes. No personal data is shared or sold."})}),(0,b.jsx)("div",{className:"text-center mt-2",children:(0,b.jsx)(d.A,{variant:"link",size:"sm",onClick:()=>{R(!Q),ae(""),ce(!1),F(null)},children:Q?"Already have an account? Sign In":"Don't have an account? Sign Up"})}),(0,b.jsx)("hr",{className:"text-secondary"}),(0,b.jsx)("div",{className:"d-grid gap-2",children:(0,b.jsxs)(d.A,{variant:"outline-light",onClick:(me=a,async()=>{try{ae(""),ie(!0);const e=await me();await he(e.user.uid)}catch(e){console.log("Auth error:",e.code,e.message),ae(A(e.code))}finally{ie(!1)}}),disabled:ne,children:[(0,b.jsx)(x.F4b,{className:"me-2"}),"Sign in with Google"]})})]})})});var me}}}]);
//# sourceMappingURL=584.26e83798.chunk.js.map