Private
Public Access
con este par de cambios ya tengo que muestra los grupos
This commit is contained in:
1 parent
617583def5
commit
0370a958b4
9 files changed
+98
-28
No files matched your search
@@ -2,7 +2,8 @@ export { login } from './hooks/login';
|
||||
export { register } from './hooks/register';
|
||||
export { obtenerUsuarios } from './hooks/obtenerUsuarios';
|
||||
export { obtenerUsuarioPorId } from './hooks/obtenerUsuarioPorId';
|
||||
export { modificarUsuario } from './hooks/updateUser';
|
||||
export { modificarUsuario } from './hooks/modificarUsuario';
|
||||
export { borrarUsuario } from './hooks/borrarUsuario';
|
||||
export { ObtenerGruposDeUsuario } from './hooks/ObtenerGruposDeUsuario';
|
||||
export { setToken, removeToken, getToken } from './hooks/token';
|
||||
export { getCurrentUser, setCurrentUser, removeCurrentUser } from './hooks/user';
|
||||
@@ -4,12 +4,13 @@
|
||||
interface Props {
|
||||
title?: string;
|
||||
children: Snippet;
|
||||
err?: Boolean;
|
||||
}
|
||||
|
||||
let { title, children }: Props = $props();
|
||||
let { title, children, err = false }: Props = $props();
|
||||
</script>
|
||||
|
||||
<div class="card">
|
||||
<div class="card {err ? 'err' : ''}">
|
||||
{#if title}
|
||||
<h2 class="card-title">{title}</h2>
|
||||
{/if}
|
||||
@@ -32,4 +33,8 @@
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
|
||||
.err {
|
||||
background: rgba(255, 0, 0, 0.7) !important;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,9 @@
|
||||
<script>
|
||||
import Card from './Card.svelte';
|
||||
|
||||
let { children } = $props();
|
||||
</script>
|
||||
|
||||
<Card err={true}>
|
||||
{@render children()}
|
||||
</Card>
|
||||
@@ -1,3 +1,24 @@
|
||||
import type { Usuario } from '../../types';
|
||||
import type { Usuario, GruposYPermisosResponse } from '../../types';
|
||||
import { API_URL } from '../env';
|
||||
import { getToken } from './token';
|
||||
|
||||
export async function ObtenerGruposDeUsuario(usu: Usuario) {}
|
||||
async function handleResponse<T>(response: Response): Promise<T> {
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ message: 'Error desconocido' }));
|
||||
throw new Error(error.message || error.error || 'Error en la petición');
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function ObtenerGruposDeUsuario(usu: Usuario): Promise<GruposYPermisosResponse> {
|
||||
const response = await fetch(`${API_URL}/usuarios/grupos-permisos`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${getToken()}`
|
||||
},
|
||||
|
||||
body: JSON.stringify({ email: usu.email })
|
||||
});
|
||||
return handleResponse<GruposYPermisosResponse>(response);
|
||||
}
|
||||
@@ -17,9 +17,14 @@ export async function login(credentials: LoginRequest): Promise<LoginResponse> {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(credentials)
|
||||
});
|
||||
const data = await handleResponse<LoginResponse>(response);
|
||||
setAuthTokens(data);
|
||||
setCurrentUser({ email: credentials.email, name: credentials.email[0] });
|
||||
const data = await handleResponse<LoginResponse & { id: number }>(response);
|
||||
setAuthTokens({
|
||||
access_token: data.access_token,
|
||||
expires_in: data.expires_in,
|
||||
refresh_token: data.refresh_token,
|
||||
token_type: data.token_type
|
||||
});
|
||||
setCurrentUser({ id: data.id, email: credentials.email, name: credentials.email[0] });
|
||||
setToken(data.access_token);
|
||||
return data;
|
||||
}
|
||||
File renamed without changes.
Reference in new issue
Block a user