mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-13 15:10:43 -03:00
terminada funcionalidad de resetear contraseña en [perfil]
This commit is contained in:
28
src/lib/hooks/cambiarContraseñaUsuario.ts
Normal file
28
src/lib/hooks/cambiarContraseñaUsuario.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { apiBase } from '@/stores/url';
|
||||
import { get } from 'svelte/store';
|
||||
import type { UserResponseDto } from '../../types';
|
||||
import { sesionStore } from '@/stores/usuario';
|
||||
|
||||
export async function cambiarContraseñaUsuario(
|
||||
oldPassword: string,
|
||||
newPassword: string,
|
||||
id: number
|
||||
) {
|
||||
try {
|
||||
const req = await fetch(`${get(apiBase)}/api/users/${id}/password`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
|
||||
},
|
||||
body: JSON.stringify({ currentPassword: oldPassword, newPassword })
|
||||
});
|
||||
if (req.ok) {
|
||||
return '';
|
||||
}
|
||||
const data = await req.json();
|
||||
return data.message;
|
||||
} catch {
|
||||
return 'No se pudo alcanzar el servidor';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user