Aggiustamenti Proxy, Impl di list.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { toTypedSchema } from '@vee-validate/zod';
|
||||
import * as zod from 'zod';
|
||||
import { FetchError } from "ofetch";
|
||||
|
||||
const zodSchema = zod.object({
|
||||
username: zod.string().min(1, { message: 'This is required' }),
|
||||
@@ -10,10 +11,23 @@ const schema = toTypedSchema(zodSchema);
|
||||
|
||||
const toast = useToast();
|
||||
|
||||
function onSubmit(v: unknown) {
|
||||
async function onSubmit(v: unknown) {
|
||||
const values = v as zod.infer<typeof zodSchema>;
|
||||
try {
|
||||
await $fetch('/api/public/1/auth/login/', {
|
||||
method: 'POST',
|
||||
body: values
|
||||
});
|
||||
} catch (e) {
|
||||
if (e instanceof FetchError) {
|
||||
toast.add({ summary: 'Error during Login', detail: e.data, severity: 'error' });
|
||||
return;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
toast.add({ summary: 'Success', detail: 'The form has been submitted.', severity: 'success' });
|
||||
console.log(values);
|
||||
await navigateTo('/user/myself');
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -26,8 +40,8 @@ function onSubmit(v: unknown) {
|
||||
<VeeForm v-slot="{isSubmitting}" :validation-schema="schema" @submit="onSubmit">
|
||||
<div class="grid grid-cols-1 gap-2">
|
||||
<FloatInputTextField name="username" label="Username"/>
|
||||
<FloatInputTextField name="password" label="Password"/>
|
||||
<Button type="submit" :loading="isSubmitting">Submit</Button>
|
||||
<FloatInputPwdField name="password" label="Password"/>
|
||||
<Button label="Submit" type="submit" :loading="isSubmitting"/>
|
||||
</div>
|
||||
</VeeForm>
|
||||
</template>
|
||||
|
||||
32
pages/user/list.vue
Normal file
32
pages/user/list.vue
Normal file
@@ -0,0 +1,32 @@
|
||||
<script setup lang="ts">
|
||||
const { data, status, error } = useFetch('/api/internal/current/users/?limit=100&is_readonly=0', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<!-- Causa useFetch va basically sempre in SSR gli stati diversi da success e error non appaiono mai. -->
|
||||
<div v-if="status === 'pending'">
|
||||
<p>LOADING...</p>
|
||||
</div>
|
||||
<div v-else-if="status === 'error'">
|
||||
<p>ERROR: {{ error }}</p>
|
||||
</div>
|
||||
<div v-else-if="status ==='success'">
|
||||
<p>DATA:</p>
|
||||
<p>{{ data }}</p>
|
||||
</div>
|
||||
<div v-else-if="status === 'idle'">
|
||||
<p>IDLE???</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user