Add database initialization
now, when the project is ran without configured database, it will prompt for the first user to configure the database and add the first user
This commit is contained in:
parent
cbfc4e9317
commit
90932a49c8
6 changed files with 286 additions and 0 deletions
62
pages/firstRun.vue
Normal file
62
pages/firstRun.vue
Normal file
|
@ -0,0 +1,62 @@
|
|||
<script setup lang="ts">
|
||||
/* global $fetch */
|
||||
import { ref } from 'vue';
|
||||
import { NuxtError, navigateTo, useFetch } from 'nuxt/app';
|
||||
import { definePageMeta } from '~/.nuxt/imports';
|
||||
|
||||
import EntryEditor, { fieldDefinition } from '~/components/entryEditor.vue';
|
||||
import Alerts, { AlertData } from '~/components/alerts.vue';
|
||||
|
||||
const editorFields: Array<fieldDefinition> = [
|
||||
{ key: "username", type: "text", label: "Username", optional: false },
|
||||
{ key: "password", type: "text", label: "Password", optional: false },
|
||||
{ key: "email", type: "text", label: "email", optional: false },
|
||||
];
|
||||
|
||||
const formValue = ref<any>({});
|
||||
const alerts = ref<Array<AlertData>>([]);
|
||||
|
||||
definePageMeta({
|
||||
layout: false,
|
||||
});
|
||||
|
||||
async function submit() {
|
||||
try {
|
||||
await $fetch("/api/firstRun", {
|
||||
body: formValue.value,
|
||||
method: "POST",
|
||||
});
|
||||
await navigateTo("/login");
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
alerts.value.push({ text: (e as NuxtError).data.message });
|
||||
}
|
||||
}
|
||||
|
||||
if (!(await useFetch("/api/firstRun")).data.value)
|
||||
await navigateTo("/login");
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Alerts :alerts="alerts" />
|
||||
<VCard max-width="450px" class="mx-auto mt-16" variant="outlined">
|
||||
<template #title>
|
||||
Initial setup
|
||||
</template>
|
||||
<template #text>
|
||||
<p>
|
||||
It looks like you've run the server with an empty or uninitialized database or with database without any users.<br>
|
||||
Below you can initialize the database register your first user and.
|
||||
</p><br>
|
||||
<EntryEditor
|
||||
:fields="editorFields"
|
||||
@update-sub-model-value="(k, v) => { formValue[k] = v }"
|
||||
/>
|
||||
</template>
|
||||
<template #actions>
|
||||
<VBtn color="primary" @click="submit">
|
||||
Initialize
|
||||
</VBtn>
|
||||
</template>
|
||||
</VCard>
|
||||
</template>
|
|
@ -19,6 +19,7 @@ const redirectTo = ref(route.redirectedFrom);
|
|||
|
||||
definePageMeta({
|
||||
layout: false,
|
||||
middleware: ["first-run"],
|
||||
});
|
||||
|
||||
async function submit() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue