changed functions for nuxt-friendly version
This commit is contained in:
@@ -27,16 +27,13 @@ const props = defineProps({
|
||||
})
|
||||
|
||||
function logout() {
|
||||
return fetch("/logout").then(
|
||||
(response) => {
|
||||
if (response.ok) {
|
||||
window.location.href = "/";
|
||||
}
|
||||
}
|
||||
)
|
||||
return $fetch("/logout").then((r) => {
|
||||
reloadNuxtApp({ path: "/" })
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
<template>
|
||||
<UHeader :toggle="false" class="pop mb-4">
|
||||
|
||||
@@ -39,20 +39,17 @@ const schema = z.object({
|
||||
type Schema = z.output<typeof schema>
|
||||
|
||||
function onSubmit(payload: FormSubmitEvent<Schema>) {
|
||||
return fetch(base_url + "/login", {
|
||||
return $fetch("/login", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type" : "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
body: {
|
||||
email: payload.data.email,
|
||||
password: payload.data.password,
|
||||
remember: payload.data.remember || false
|
||||
})
|
||||
}).then((response) => {
|
||||
if (response.ok)
|
||||
window.location.href = "/";
|
||||
else if (response.status == 401) {
|
||||
}
|
||||
}).then((r) => {
|
||||
reloadNuxtApp({path: "/"});
|
||||
}).catch((err) => {
|
||||
if(err.data.statusCode == 401) {
|
||||
wrong_login.value = true;
|
||||
// show for 5 seconds
|
||||
setTimeout(() => wrong_login.value = false, 5000);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import * as z from 'zod'
|
||||
import type { FormSubmitEvent } from '@nuxt/ui'
|
||||
import urlJoin from "url-join"
|
||||
|
||||
definePageMeta({
|
||||
layout: "settings",
|
||||
@@ -27,7 +28,7 @@
|
||||
|
||||
async function submitChanges(event: FormSubmitEvent<Schema>) {
|
||||
loading_btn.value = true
|
||||
await fetch(base_url + "/settings/edit_user", {
|
||||
await fetch(urlJoin(conf.app.baseURL, "/settings/edit_user"), {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import * as z from 'zod'
|
||||
import type { FormSubmitEvent } from '@nuxt/ui'
|
||||
import urlJoin from 'url-join'
|
||||
|
||||
definePageMeta({
|
||||
layout: "settings",
|
||||
@@ -9,7 +10,7 @@
|
||||
const loading_btn = ref(false)
|
||||
const toast = useToast()
|
||||
const config = useRuntimeConfig()
|
||||
const base_url = config.app.baseURL.endsWith('/') ? config.app.baseURL.slice(0, -1) : config.app.baseURL
|
||||
//const base_url = config.app.baseURL.endsWith('/') ? config.app.baseURL.slice(0, -1) : config.app.baseURL
|
||||
|
||||
|
||||
const schema = z.object({
|
||||
@@ -34,7 +35,7 @@
|
||||
async function submitChanges(event: FormSubmitEvent<Schema>) {
|
||||
loading_btn.value = true
|
||||
try {
|
||||
fetch(base_url + "/settings/changepw", {
|
||||
fetch(urlJoin(config.app.baseURL,"/settings/changepw"), {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
@@ -51,10 +52,10 @@
|
||||
}
|
||||
else {
|
||||
const body = await response.json()
|
||||
console.log(body)
|
||||
console.log(body.statusMessage || "")
|
||||
toast.add({
|
||||
title: 'Error',
|
||||
description : body.data.detail || 'Something went wrong',
|
||||
description : body.data?.detail || body.statusMessage || 'Something went wrong',
|
||||
color: 'error'
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user