mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-09-26 02:35:48 -05:00
fix: clean up some api things
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user