fix: clean up some api things

This commit is contained in:
niko
2025-04-25 21:32:17 -04:00
parent 26817d5fbc
commit 1e3d27db29
3 changed files with 23 additions and 19 deletions

View File

@@ -9,22 +9,27 @@ const loginForm = reactive({ username: '', password: '' });
const errorMessage = ref<string | null>();
async function loginSubmission() {
await $fetch('/api/account/login', {
method: 'POST',
body: loginForm
}).catch((error: FetchError) => {
errorMessage.value = error.statusText;
setTimeout(() => { // TODO: this is not the best way to clear this out, but this is temporary! replace all toasts with input alerts in the future
try {
await $fetch('/api/account/login', {
method: 'POST',
body: loginForm
});
if (typeof redirect.value === 'string') {
await navigateTo(redirect.value);
} else {
await navigateTo('/account');
}
} catch (error: unknown) {
if (error instanceof FetchError) {
errorMessage.value = error.statusText;
} else {
errorMessage.value = `Error during registration: ${error}`; // TODO: localize
}
setTimeout(() => { // TODO: replace this toast
errorMessage.value = null;
}, 5000);
return;
});
if (typeof redirect.value === 'string') {
await navigateTo(redirect.value);
} else {
await navigateTo('/account');
}
}
</script>

View File

@@ -1,11 +1,11 @@
import { FetchError } from 'ofetch';
type LoginCCResponse = {
interface LoginCCResponse {
refresh_token: string;
access_token: string;
token_type: string;
expires_in: number;
};
}
export default defineEventHandler(async (event) => {
const body = await readBody(event);

View File

@@ -1,12 +1,11 @@
import { FetchError } from 'ofetch';
// TODO: Drop to interface from type, type is unnecessary for this
type RegisterCCResponse = { // TODO: this is the same as the login response. figure out where we should put types and merge into AuthCCReponse!
interface RegisterCCResponse { // TODO: this is the same as the login response. figure out where we should put types and merge into AuthCCReponse!
refresh_token: string;
access_token: string;
token_type: string;
expires_in: number;
};
}
export default defineEventHandler(async (event) => {
const body = await readBody(event);