mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-01 13:10:44 -03:00
refactor
This commit is contained in:
@@ -1,36 +1,38 @@
|
||||
import { apiBase } from "@/stores/url";
|
||||
import { goto } from "$app/navigation";
|
||||
import type { RegisterDto } from "../../types";
|
||||
import { apiBase } from '@/stores/url';
|
||||
import { goto } from '$app/navigation';
|
||||
import type { RegisterDto } from '../../types';
|
||||
|
||||
export async function register(e: SubmitEvent, dto: RegisterDto, callbackfn:()=>void){
|
||||
e.preventDefault();
|
||||
if (dto.password == "" || dto.username == "" ||
|
||||
!dto.email?.includes("@") || dto.displayName=="") return;
|
||||
try {
|
||||
export async function register(e: SubmitEvent, dto: RegisterDto, callbackfn: () => void) {
|
||||
e.preventDefault();
|
||||
if (
|
||||
dto.password == '' ||
|
||||
dto.username == '' ||
|
||||
!dto.email?.includes('@') ||
|
||||
dto.displayName == ''
|
||||
)
|
||||
return;
|
||||
try {
|
||||
const { subscribe } = apiBase;
|
||||
let baseUrl: string = '';
|
||||
|
||||
const { subscribe } = apiBase;
|
||||
let baseUrl: string = '';
|
||||
|
||||
subscribe((value) => {
|
||||
baseUrl = value;
|
||||
})();
|
||||
const req = await fetch(baseUrl + "/api/auth/register", {
|
||||
method: "POST",
|
||||
headers:{
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(dto)
|
||||
});
|
||||
if (req.ok) {
|
||||
const data= await req.json();
|
||||
goto("/login?msg="+data.message);
|
||||
} else {
|
||||
callbackfn();
|
||||
}
|
||||
|
||||
} catch {
|
||||
callbackfn();
|
||||
console.error("fallo al intentar alcanzar el servidor")
|
||||
|
||||
}
|
||||
subscribe((value) => {
|
||||
baseUrl = value;
|
||||
})();
|
||||
const req = await fetch(baseUrl + '/api/auth/register', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(dto)
|
||||
});
|
||||
if (req.ok) {
|
||||
const data = await req.json();
|
||||
goto('/login?msg=' + data.message);
|
||||
} else {
|
||||
callbackfn();
|
||||
}
|
||||
} catch {
|
||||
callbackfn();
|
||||
console.error('fallo al intentar alcanzar el servidor');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user