Compare commits

...

5 commits

Author SHA1 Message Date
187e432182 pages/login: await when "updating" user info for the first time
All checks were successful
Build dev / build (push) Successful in 1m9s
2023-12-20 06:03:56 +01:00
f11b4c9a75 page/login: update cookie from useCookie on login/logout
I think this fixes an issue where auth token cookie
gets deleted when page is not being refreshed
after login.
2023-12-20 06:03:12 +01:00
eabb7b89c7 replace all $fetch with useRequestFetch 2023-12-20 05:45:29 +01:00
015b66706f Update dependencies 2023-12-20 05:26:19 +01:00
f308ab80c9 Use one format for slashes prepend/append where fetch is used
always prepend slash
never append slash
2023-12-20 05:06:38 +01:00
8 changed files with 370 additions and 348 deletions

649
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -17,14 +17,14 @@
"@typescript-eslint/parser": "^6.9.1", "@typescript-eslint/parser": "^6.9.1",
"eslint": "^8.39.0", "eslint": "^8.39.0",
"nuxt": "3.8.2", "nuxt": "3.8.2",
"prisma": "5.7.0", "prisma": "5.7.1",
"sass": "^1.62.0", "sass": "^1.62.0",
"vite-plugin-vuetify": "^2.0.1", "vite-plugin-vuetify": "^2.0.1",
"vuetify": "^3.1.15" "vuetify": "^3.1.15"
}, },
"dependencies": { "dependencies": {
"@prisma/client": "5.7.0", "@prisma/client": "5.7.1",
"@prisma/engines": "^5.7.0", "@prisma/engines": "5.7.1",
"@prisma/migrate": "5.7.0" "@prisma/migrate": "5.7.1"
} }
} }

View file

@ -1,6 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
/* global $fetch */
import { useRoute, useFetch, createError } from "nuxt/app";
import { ref, type Ref } from "vue"; import { ref, type Ref } from "vue";
import { VBtn, VForm } from "vuetify/components"; import { VBtn, VForm } from "vuetify/components";
@ -9,7 +7,10 @@ import Snowflake from "~/utils/snowflake";
import OrderView from "~/components/orderView.vue"; import OrderView from "~/components/orderView.vue";
import EntryEditor, { type fieldDefinition } from "~/components/entryEditor.vue"; import EntryEditor, { type fieldDefinition } from "~/components/entryEditor.vue";
import { useRoute, useFetch, createError, useRequestFetch } from "#imports";
const route = useRoute(); const route = useRoute();
const fetch = useRequestFetch();
const id = route.params.id; const id = route.params.id;
const clientRequest = await useFetch(`/api/clients/${id}` as "/api/clients/:id"); const clientRequest = await useFetch(`/api/clients/${id}` as "/api/clients/:id");
@ -38,7 +39,7 @@ async function loadOrder(id: string) {
if (!entry) throw createError(`excepted order entry for ${id}`); if (!entry) throw createError(`excepted order entry for ${id}`);
entry.loading = true; entry.loading = true;
// @ts-expect-error // @ts-expect-error
entry.value = await $fetch(`/api/orders/${id}` as "/api/order/:id", { entry.value = await fetch(`/api/orders/${id}` as "/api/order/:id", {
method: "GET", method: "GET",
}) as Order; }) as Order;
entry.loading = false; entry.loading = false;
@ -77,7 +78,7 @@ async function handleSubmit() {
submitting.value = true; submitting.value = true;
normalizeForm(); normalizeForm();
try { try {
const result = await $fetch( const result = await fetch(
`/api/clients/${client.value.id}` as "/api/clients/:id", { `/api/clients/${client.value.id}` as "/api/clients/:id", {
method: "PATCH", method: "PATCH",
body: formData.value, body: formData.value,

View file

@ -1,5 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
/* global $fetch */
import { type NuxtError } from "nuxt/app"; import { type NuxtError } from "nuxt/app";
import { ref, type Ref, reactive } from "vue"; import { ref, type Ref, reactive } from "vue";
import { VBtn } from "vuetify/components"; import { VBtn } from "vuetify/components";
@ -8,10 +7,11 @@ import pagedTable from "~/components/pagedTable.vue";
import Alerts, { type AlertData } from "~/components/alerts.vue"; import Alerts, { type AlertData } from "~/components/alerts.vue";
import { type fieldDefinition } from "~/components/entryEditor.vue"; import { type fieldDefinition } from "~/components/entryEditor.vue";
import { useFetch, createError, navigateTo, useRoute, definePageMeta } from "#imports"; import { useFetch, createError, navigateTo, useRoute, definePageMeta, useRequestFetch } from "#imports";
definePageMeta({ middleware: ["auth"] }); definePageMeta({ middleware: ["auth"] });
const route = useRoute(); const route = useRoute();
const fetch = useRequestFetch();
const alerts = ref<Array<AlertData>>([]); const alerts = ref<Array<AlertData>>([]);
@ -32,7 +32,7 @@ async function rowClicked(client: string, edit = false) {
async function rowDelete(client: string) { async function rowDelete(client: string) {
try { try {
await $fetch(`/api/clients/${client}` as "api/clients/:id", { await fetch(`/api/clients/${client}` as "/api/clients/:id", {
method: "DELETE", method: "DELETE",
}); });
clients.value = clients.value.filter(e => e.id !== client); clients.value = clients.value.filter(e => e.id !== client);
@ -48,7 +48,7 @@ async function loadBefore() {
loadingMore.value = true; loadingMore.value = true;
try { try {
clients.value.push(...await $fetch("/api/clients", { clients.value.push(...await fetch("/api/clients", {
query: { query: {
before: clients.value[clients.value.length - 1].id, before: clients.value[clients.value.length - 1].id,
}, },
@ -91,8 +91,8 @@ async function handleSubmit() {
submitting.value = true; submitting.value = true;
normalizeForm(); normalizeForm();
try { try {
const result = await $fetch( const result = await fetch(
"/api/clients/", { "/api/clients", {
method: "POST", method: "POST",
body: formData.value, body: formData.value,
}, },

View file

@ -1,8 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
/* global $fetch */
import { ref } from 'vue'; import { ref } from 'vue';
import { type NuxtError } from 'nuxt/app'; import { type NuxtError } from 'nuxt/app';
import { navigateTo, useFetch, definePageMeta } from '#imports'; import { navigateTo, useFetch, definePageMeta, useRequestFetch } from '#imports';
import EntryEditor, { type fieldDefinition } from '~/components/entryEditor.vue'; import EntryEditor, { type fieldDefinition } from '~/components/entryEditor.vue';
import Alerts, { type AlertData } from '~/components/alerts.vue'; import Alerts, { type AlertData } from '~/components/alerts.vue';
@ -22,7 +21,7 @@ definePageMeta({
async function submit() { async function submit() {
try { try {
await $fetch("/api/firstRun", { await useRequestFetch()("/api/firstRun", {
body: formValue.value, body: formValue.value,
method: "POST", method: "POST",
}); });

View file

@ -1,18 +1,22 @@
<script setup lang="ts"> <script setup lang="ts">
/* global $fetch */
import { ref, watch } from "vue"; import { ref, watch } from "vue";
import { VForm } from "vuetify/components"; import { VForm } from "vuetify/components";
import { type CookieRef } from "#app";
import { cookieSettings } from "~/utils/cookieSettings"; import { cookieSettings } from "~/utils/cookieSettings";
import { definePageMeta, navigateTo, useCookie, useFetch, useRoute } from "#imports"; import { definePageMeta, navigateTo, useCookie, useFetch, useRoute, useRequestFetch, useRequestEvent } from "#imports";
const route = useRoute(); const route = useRoute();
const fetch = useRequestFetch();
const login = ref(""); const login = ref("");
const password = ref(""); const password = ref("");
const loading = ref(false); const loading = ref(false);
const error = ref<true | string>(true); const error = ref<true | string>(true);
const form = ref<VForm | null>(null); const form = ref<VForm | null>(null);
const loggedIn = ref<boolean>(useCookie("token", cookieSettings).value != null); const tokenCookie = useCookie("token", cookieSettings) as CookieRef<string | undefined>;
const loggedIn = ref<boolean>(tokenCookie.value !== undefined);
watch(tokenCookie, (v) => { loggedIn.value = v !== undefined; });
const redirectTo = ref(route.redirectedFrom); const redirectTo = ref(route.redirectedFrom);
@ -24,12 +28,12 @@ definePageMeta({
async function submit() { async function submit() {
loading.value = true; loading.value = true;
try { try {
const result = await $fetch("/api/login", { const result = await fetch("/api/login", {
body: { login: login.value, password: password.value }, body: { login: login.value, password: password.value },
method: "POST", method: "POST",
}); });
console.log(result); console.log(result);
loggedIn.value = true; tokenCookie.value = result.token;
password.value = ""; password.value = "";
} catch (e) { } catch (e) {
console.log(typeof e); console.log(typeof e);
@ -44,9 +48,10 @@ async function submit() {
async function logout() { async function logout() {
try { try {
await $fetch("/api/logout"); await fetch("/api/logout");
loggedIn.value = false; loggedIn.value = false;
} catch (e) { } catch (e) {
tokenCookie.value = undefined;
console.error(e); console.error(e);
} }
} }
@ -56,7 +61,7 @@ watch(loggedIn, updateUserInfo);
async function updateUserInfo() { async function updateUserInfo() {
if (loggedIn.value) { if (loggedIn.value) {
try { try {
userInfo.value = JSON.stringify(await $fetch("/api/users/me")); userInfo.value = JSON.stringify(await fetch("/api/users/me"));
} catch (e) { } catch (e) {
// expected if the user is not logged in // expected if the user is not logged in
userInfo.value = ""; userInfo.value = "";
@ -66,7 +71,7 @@ async function updateUserInfo() {
} }
} }
updateUserInfo(); await updateUserInfo();
</script> </script>
<template> <template>

View file

@ -1,5 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
/* global $fetch */
import { ref, type Ref } from "vue"; import { ref, type Ref } from "vue";
import { VBtn } from "vuetify/components"; import { VBtn } from "vuetify/components";
import type { NuxtError } from "#app"; import type { NuxtError } from "#app";
@ -7,10 +6,11 @@ import type { NuxtError } from "#app";
import Alerts, { type AlertData } from "~/components/alerts.vue"; import Alerts, { type AlertData } from "~/components/alerts.vue";
import { type fieldDefinition } from "~/components/entryEditor.vue"; import { type fieldDefinition } from "~/components/entryEditor.vue";
import { definePageMeta, useFetch, createError, useRoute, navigateTo } from "#imports"; import { definePageMeta, useFetch, createError, useRoute, navigateTo, useRequestFetch } from "#imports";
definePageMeta({ middleware: ["auth"] }); definePageMeta({ middleware: ["auth"] });
const route = useRoute(); const route = useRoute();
const fetch = useRequestFetch();
const alerts = ref<Array<AlertData>>([]); const alerts = ref<Array<AlertData>>([]);
@ -33,7 +33,7 @@ async function rowClicked(client: string, edit = false) {
async function rowDelete(client: string) { async function rowDelete(client: string) {
try { try {
await $fetch(`/api/orders/${client}` as "api/orders/:id", { await fetch(`/api/orders/${client}` as "/api/orders/:id", {
method: "DELETE", method: "DELETE",
}); });
orders.value = orders.value.filter(e => e.id !== client); orders.value = orders.value.filter(e => e.id !== client);
@ -49,7 +49,7 @@ async function loadBefore() {
loadingMore.value = true; loadingMore.value = true;
try { try {
orders.value.push(...await $fetch("/api/orders", { orders.value.push(...await fetch("/api/orders", {
query: { query: {
before: orders.value[orders.value.length - 1].id, before: orders.value[orders.value.length - 1].id,
}, },
@ -87,7 +87,7 @@ async function handleSubmit() {
submitting.value = true; submitting.value = true;
normalizeForm(); normalizeForm();
try { try {
const result = await $fetch( const result = await fetch(
"/api/orders", { "/api/orders", {
method: "POST", method: "POST",
body: formData.value, body: formData.value,

View file

@ -4,12 +4,12 @@ let
# Updating this package will force an update for nodePackages.prisma. The # Updating this package will force an update for nodePackages.prisma. The
# version of prisma-engines and nodePackages.prisma must be the same for them to # version of prisma-engines and nodePackages.prisma must be the same for them to
# function correctly. # function correctly.
prisma-version = "5.7.0"; prisma-version = "5.7.1";
prisma-src = pkgs.fetchFromGitHub { prisma-src = pkgs.fetchFromGitHub {
owner = "prisma"; owner = "prisma";
repo = "prisma-engines"; repo = "prisma-engines";
rev = prisma-version; rev = prisma-version;
hash = "sha256-gZEz0UtgNwumsZbweAyx3TOVHJshpBigc9pzWN7Gb/A="; hash = "sha256-EOYbWUgoc/9uUtuocfWDh0elExzL0+wb4PsihgMbsWs=";
}; };
new-prisma-engines = pkgs.rustPlatform.buildRustPackage { new-prisma-engines = pkgs.rustPlatform.buildRustPackage {
pname = "prisma-engines"; pname = "prisma-engines";