Files
warren/frontend/lib/api/auth/register.ts
2025-07-20 13:14:31 +02:00

43 lines
1016 B
TypeScript

import { toast } from 'vue-sonner';
import type { ApiResponse } from '#shared/types/api';
export async function registerUser(
username: string,
email: string,
password: string
): Promise<{ success: boolean }> {
const { data, error } = await useFetch<ApiResponse<undefined>>(
getApiUrl('auth/register'),
{
method: 'POST',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({
name: username,
email: email,
password: password,
}),
responseType: 'json',
}
);
if (data.value == null) {
toast.error('Register', {
description: error.value?.data ?? 'Failed to register',
});
return {
success: false,
};
}
toast.success('Register', {
description: `Successfully registered user ${username}`,
});
return {
success: true,
};
}