8f5730c3f6
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | #202 | Authentification — Connexion utilisateur (JWT) | ## Description de la PR [#202] Authentification — Connexion utilisateur (JWT) ## Modification du .env ## Check list - [x] Pas de régression - [ ] TU/TI/TF rédigée - [x] TU/TI/TF OK - [x] CHANGELOG modifié Reviewed-on: https://gitea.malio.fr/MALIO-DEV/Ferme/pulls/5 Reviewed-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr> Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
39 lines
980 B
TypeScript
39 lines
980 B
TypeScript
import { useApi } from '~/composables/useApi'
|
|
import type { UserData } from '~/services/dto/user-data'
|
|
|
|
export async function getUsers() {
|
|
const api = useApi()
|
|
const data = await api.get<UserData[] | { 'hydra:member': UserData[] }>('users', {}, {
|
|
toastErrorKey: 'errors.auth.users'
|
|
})
|
|
if (Array.isArray(data)) {
|
|
return data
|
|
}
|
|
|
|
return data['hydra:member'] ?? []
|
|
}
|
|
|
|
export async function getCurrentUser() {
|
|
const api = useApi()
|
|
return api.get<UserData>('me', {}, {
|
|
toast: false
|
|
})
|
|
}
|
|
|
|
export async function login(username: string, password: string) {
|
|
const api = useApi()
|
|
return api.post<{ token: string }>('login_check', { username, password }, {
|
|
toastErrorKey: 'errors.auth.login',
|
|
toastSuccessKey: 'success.auth.login'
|
|
})
|
|
}
|
|
|
|
export async function logout() {
|
|
const api = useApi()
|
|
return api.post<void>('logout', {}, {
|
|
toastErrorKey: 'errors.auth.logout',
|
|
toastSuccessKey: 'success.auth.logout',
|
|
redirect: 'manual'
|
|
})
|
|
}
|