This commit is contained in:
2026-01-01 22:39:57 -03:00
parent 90b2b7a72c
commit 343e072837
+35 -33
View File
@@ -1,36 +1,38 @@
import { apiBase } from "@/stores/url"; import { apiBase } from '@/stores/url';
import { goto } from "$app/navigation"; import { goto } from '$app/navigation';
import type { RegisterDto } from "../../types"; import type { RegisterDto } from '../../types';
export async function register(e: SubmitEvent, dto: RegisterDto, callbackfn:()=>void){ export async function register(e: SubmitEvent, dto: RegisterDto, callbackfn: () => void) {
e.preventDefault(); e.preventDefault();
if (dto.password == "" || dto.username == "" || if (
!dto.email?.includes("@") || dto.displayName=="") return; dto.password == '' ||
try { dto.username == '' ||
!dto.email?.includes('@') ||
dto.displayName == ''
)
return;
try {
const { subscribe } = apiBase;
let baseUrl: string = '';
const { subscribe } = apiBase; subscribe((value) => {
let baseUrl: string = ''; baseUrl = value;
})();
subscribe((value) => { const req = await fetch(baseUrl + '/api/auth/register', {
baseUrl = value; method: 'POST',
})(); headers: {
const req = await fetch(baseUrl + "/api/auth/register", { 'Content-Type': 'application/json'
method: "POST", },
headers:{ body: JSON.stringify(dto)
"Content-Type": "application/json" });
}, if (req.ok) {
body: JSON.stringify(dto) const data = await req.json();
}); goto('/login?msg=' + data.message);
if (req.ok) { } else {
const data= await req.json(); callbackfn();
goto("/login?msg="+data.message); }
} else { } catch {
callbackfn(); callbackfn();
} console.error('fallo al intentar alcanzar el servidor');
}
} catch {
callbackfn();
console.error("fallo al intentar alcanzar el servidor")
}
} }