This commit is contained in:
2026-01-01 22:39:57 -03:00
parent 90b2b7a72c
commit 343e072837
+18 -16
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 == '' ||
dto.username == '' ||
!dto.email?.includes('@') ||
dto.displayName == ''
)
return;
try { try {
const { subscribe } = apiBase; const { subscribe } = apiBase;
let baseUrl: string = ''; let baseUrl: string = '';
subscribe((value) => { subscribe((value) => {
baseUrl = value; baseUrl = value;
})(); })();
const req = await fetch(baseUrl + "/api/auth/register", { const req = await fetch(baseUrl + '/api/auth/register', {
method: "POST", method: 'POST',
headers:{ headers: {
"Content-Type": "application/json" 'Content-Type': 'application/json'
}, },
body: JSON.stringify(dto) body: JSON.stringify(dto)
}); });
if (req.ok) { if (req.ok) {
const data= await req.json(); const data = await req.json();
goto("/login?msg="+data.message); goto('/login?msg=' + data.message);
} else { } else {
callbackfn(); callbackfn();
} }
} catch { } catch {
callbackfn(); callbackfn();
console.error("fallo al intentar alcanzar el servidor") console.error('fallo al intentar alcanzar el servidor');
} }
} }