Fixes token checking
All checks were successful
Gitea Build Action / build-go (push) Successful in 25s
Gitea Build Action / build-nuxt (push) Successful in 10m1s

This commit is contained in:
Daniel Svitan
2025-06-05 16:57:02 +02:00
parent 48e433ff1e
commit 7b99b75def
4 changed files with 50 additions and 18 deletions

View File

@@ -14,44 +14,62 @@
/>
</UFormField>
<UButton type="submit" size="xl"> Submit </UButton>
<UButton type="submit" size="xl"> Submit</UButton>
</UForm>
</main>
</template>
<script lang="ts" setup>
import * as v from "valibot";
import type { FormSubmitEvent } from "@nuxt/ui";
import * as v from "valibot"
import type { FormSubmitEvent } from "@nuxt/ui"
const token = useToken();
const token = useToken()
const schema = v.object({
token: v.pipe(v.string(), v.nonEmpty("Please enter your token")),
});
type Schema = v.InferOutput<typeof schema>;
})
type Schema = v.InferOutput<typeof schema>
const state = reactive({
token: "",
});
const toast = useToast();
})
const toast = useToast()
async function onSubmit(event: FormSubmitEvent<Schema>) {
const token = event.data.token;
const res = await $fetch("https://door.svitan.dev/open", {
const received = event.data.token
await $fetch("https://door.svitan.dev/open", {
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
Authorization: `Bearer ${received}`,
},
});
console.log(token);
console.log(res);
toast.add({ title: "Token saved", color: "success" });
async onRequestError({ error }) {
toast.add({
title: "Error occurred",
description: error.message,
color: "error",
})
},
async onResponse({ response }) {
if (response.status === 200) {
toast.add({ title: "Token saved", color: "success" })
token.value = received
navigateTo("/")
} else if (response.status === 401) {
toast.add({ title: "Token not valid", color: "error" })
} else {
toast.add({
title: "Error occurred",
description: await response.text(),
color: "error",
})
}
},
})
}
onMounted(() => {
if (token.value) {
return navigateTo("/");
return navigateTo("/")
}
});
})
</script>