mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-24 16:44:28 -03:00
refactor
This commit is contained in:
+18
-16
@@ -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');
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user