register users

This commit is contained in:
2025-07-16 18:37:26 +02:00
parent 990f196984
commit be362326aa
48 changed files with 1002 additions and 64 deletions

View File

View File

@@ -0,0 +1,42 @@
import { toast } from 'vue-sonner';
import type { ApiResponse } from '~/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,
};
}