Private
Public Access
fix+feat: añadido crear usuario y separado en componentes los modals
This commit is contained in:
1 parent
eff116fab0
commit
62ec25b768
14 files changed
+387
-131
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { API_URL } from '$lib/env';
|
||||
import { getToken } from './token';
|
||||
|
||||
export async function cambiarContraseña(dto: {
|
||||
user_id: number;
|
||||
old_password: string;
|
||||
new_password: string;
|
||||
}) {
|
||||
if (
|
||||
!dto.old_password ||
|
||||
!dto.new_password ||
|
||||
dto.old_password.length < 8 ||
|
||||
dto.new_password.length < 8
|
||||
)
|
||||
return 'Las contraseñas no alcanzan el minimo de 8 caracteres';
|
||||
try {
|
||||
const req = await fetch(`${API_URL}/auth/cambiar-contraseña`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${getToken()}`
|
||||
},
|
||||
body: JSON.stringify(dto)
|
||||
});
|
||||
|
||||
let data = await req.json();
|
||||
if (!req.ok) {
|
||||
return data.error || 'Error';
|
||||
}
|
||||
invalidate('usuarios:load');
|
||||
return 'Ok';
|
||||
} catch {
|
||||
return 'No se pudo conectar con el servidor';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user