primera iteracion de login + register con google funcionales

This commit is contained in:
2026-01-20 02:56:58 -03:00
parent d89e2960d7
commit 2b2b5ad61f
8 changed files with 331 additions and 27 deletions

View File

@@ -0,0 +1,30 @@
import { apiBase } from '@/stores/url';
import type { LoginSsoDto, Sesion } from '../../types';
import { sesionStore } from '@/stores/usuario';
import { goto } from '$app/navigation';
import { get } from 'svelte/store';
export async function loginFirebase(dto: LoginSsoDto, callbackfn: () => void) {
if (dto.accessToken == '' || dto.uid == '') return;
try {
const req = await fetch(get(apiBase) + '/api/auth/login/sso', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
credentials: 'include',
body: JSON.stringify(dto)
});
if (req.ok) {
const token: Sesion = await req.json();
console.log(token);
sesionStore.set(token);
goto('/');
} else {
callbackfn();
}
} catch {
// callbackfn();
console.error('fallo al intentar alcanzar el servidor');
}
}

View File

@@ -0,0 +1,30 @@
import { apiBase } from '@/stores/url';
import { goto } from '$app/navigation';
import type { RegisterDto, RegisterSsoDto } from '../../types';
import { get } from 'svelte/store';
export async function registerFirebase(
dto: RegisterSsoDto,
callbackfn: () => void,
admin: boolean = false
) {
if (dto.uid == '' || dto.token == '' || !dto.email?.includes('@') || dto.username == '') return;
try {
const req = await fetch(get(apiBase) + '/api/auth/register/sso', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(dto)
});
if (req.ok) {
const data = await req.json();
if (!admin) goto('/login?msg=' + data.message);
} else {
callbackfn();
}
} catch {
callbackfn();
console.error('fallo al intentar alcanzar el servidor');
}
}