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