🔨 Replaces native fetch with axios
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
<script lang="ts" setup>
|
||||
import * as v from "valibot"
|
||||
import type { FormSubmitEvent } from "@nuxt/ui"
|
||||
import axios from "axios"
|
||||
|
||||
const token = useToken()
|
||||
|
||||
@@ -35,20 +36,20 @@ const state = reactive({
|
||||
})
|
||||
const toast = useToast()
|
||||
|
||||
async function onSubmit(event: FormSubmitEvent<Schema>) {
|
||||
function onSubmit(event: FormSubmitEvent<Schema>) {
|
||||
const received = event.data.token
|
||||
await $fetch(useAPI("/open"), {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${received}`,
|
||||
},
|
||||
onRequestError: handleRequestError,
|
||||
onResponse: handleResponse(() => {
|
||||
toast.add({ title: "Token saved", color: "success" })
|
||||
token.value = received
|
||||
navigateTo("/")
|
||||
}),
|
||||
})
|
||||
axios
|
||||
.get<boolean>(useAPI("/open"), {
|
||||
headers: useHeaders(received),
|
||||
})
|
||||
.then((res) => {
|
||||
handleResponse(res, () => {
|
||||
toast.add({ title: "Token saved", color: "success" })
|
||||
token.value = received
|
||||
navigateTo("/")
|
||||
})
|
||||
})
|
||||
.catch(handleRequestError)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
Reference in New Issue
Block a user