mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-01 13:10:44 -03:00
29 lines
731 B
TypeScript
29 lines
731 B
TypeScript
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';
|
|
}
|
|
}
|