Files
pockethost/dist/dashboard/_app/immutable/chunks/database.5ddaa35e.js
2023-11-01 21:27:41 -07:00

2 lines
2.4 KiB
JavaScript

import{j as L}from"./singletons.430f5ae5.js";import{c as r,L as m}from"./index.56f88796.js";const u=L("goto"),i=(t,a)=>{const{parseError:n}=r(),{dbg:o,error:e,warn:c}=m();if(e(`Form error: ${t}`,{error:t}),a){const d=n(t)[0];a(d||"Unknown message")}else throw t},y=async(t,a,n,o=!0)=>{const{authViaEmail:e}=r();n==null||n("");try{await e(t,a),o&&await u("/")}catch(c){if(!(c instanceof Error))throw new Error(`Expected Error type here, but got ${typeof c}:${c}`);i(c,n)}},$=async(t,a,n)=>{const{createUser:o}=r();n==null||n("");try{await o(t,a)}catch(e){i(e,n)}},I=async(t,a)=>{const{confirmVerification:n}=r();a==null||a("");try{await n(t),window.location.href="/"}catch(o){i(o,a)}return!1},P=async(t,a)=>{const{requestPasswordReset:n}=r();a==null||a("");try{return await n(t)}catch(o){i(o,a)}return!1},U=async(t,a,n)=>{const{requestPasswordResetConfirm:o}=r();n==null||n("");try{await o(t,a),await u("/")}catch(e){i(e,n)}return!1},b=async(t,a)=>{const{user:n,createInstance:o}=r(),{id:e}=n()||{};try{if(!t)throw new Error("Instance name is required");if(!e)throw new Error("Must be logged in to create an instance");const c=await o({subdomain:t});await u(`/app/instances/${c.instance.id}`)}catch(c){i(c,a)}},A=async(t,a,n,o=e=>{})=>{const{dbg:e,error:c,warn:d}=m(),{user:p,parseError:l}=r();try{await y(t,a,void 0,!1).then(()=>{e(`Account ${t} already exists. Logged in.`)}).catch(s=>(d("Login failed, attempting account creation."),$(t,a).then(()=>(e("Account created, proceeding to log in."),y(t,a,void 0,!1).then(()=>{e("Logged in after account creation")}).catch(h=>{throw c("Panic, auth system down"),new Error("Login system is currently down. Please contact us so we can fix this.")}))).catch(h=>{d("User input error");const w=l(h);throw new Error(`Account creation: ${w[0]}`)}))),e("User before instance creation is ",p()),await b(n).then(()=>{e(`Creation of ${n} succeeded`)}).catch(s=>{var w,f,g;if(d(`Creation of ${n} failed`),((g=(f=(w=s.data)==null?void 0:w.data)==null?void 0:f.subdomain)==null?void 0:g.code)==="validation_not_unique")throw new Error("Instance name already taken.");const h=l(s);throw new Error(`Instance creation: ${h[0]}`)})}catch(s){s("Caught widget error",{error:s}),i(s,o)}},q=async(t=a=>{})=>{const{resendVerificationEmail:a}=r();try{await a()}catch(n){i(n,t)}},C=()=>{const{logOut:t}=r();t()},x=()=>{C(),window.location.href="/"};export{y as a,A as b,q as c,b as d,I as e,P as f,U as g,x as h,$ as i,i as j};