Files
warren/frontend/lib/api/auth/login.ts
2025-07-17 16:36:36 +02:00

43 lines
1012 B
TypeScript

import { toast } from 'vue-sonner';
import type { ApiResponse } from '~/types/api';
export async function loginUser(
email: string,
password: string
): Promise<{ success: boolean }> {
const { data, error } = await useFetch<ApiResponse<{ token: string }>>(
getApiUrl('auth/login'),
{
method: 'POST',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({
email: email,
password: password,
}),
responseType: 'json',
}
);
if (data.value == null) {
toast.error('Login', {
description: error.value?.data ?? 'Failed to login',
});
return {
success: false,
};
}
useAuthSession().value = { type: 'WarrenAuth', id: data.value.data.token };
toast.success('Login', {
description: `Successfully logged in`,
});
return {
success: true,
};
}