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>( 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, }; }