refactor: better project structure
All checks were successful
Deploy WordPress and Nuxt / deploy (push) Successful in 6m3s

This commit is contained in:
2025-09-17 08:41:42 -04:00
parent ba42386645
commit 346890c088
19 changed files with 90 additions and 124 deletions

View File

@@ -0,0 +1,57 @@
import type { FormSubmitEvent } from "@nuxt/ui";
export function useAuth() {
const toast = useToast();
const redirect = useRoute().query.redirect as string || "/";
const router = useRouter();
const { fetch: refreshUserSession } = useUserSession();
// Login form
const loginFields = [
{
name: "email",
type: "text" as const,
label: "Courriel",
placeholder: "Entrez votre courriel",
required: true,
}, {
name: "password",
label: "Mot de passe",
type: "password" as const,
placeholder: "Entrez votre mot de passe",
required: true,
},
];
async function onLoginSubmit({ data }: FormSubmitEvent<LoginOutput>) {
try {
const result = await $fetch<{ success: boolean; message?: string }>("/api/login", { method: "POST", body: data });
if (!result.success) {
throw new Error(result.message || "Une erreur est survenue.");
}
await router.push(redirect);
await refreshUserSession();
}
catch (error) {
const message = error instanceof Error ? error.message : "Une erreur est survenue.";
toast.add({ title: "Échec de la connexion", description: message, color: "error" });
}
}
// Logout action
async function onLogoutClick() {
try {
const result = await $fetch("/api/logout", { method: "POST" });
if (!result.success) {
throw new Error("Une erreur est survenue.");
}
await router.push(redirect);
await refreshUserSession();
}
catch (error) {
const message = error instanceof Error ? error.message : "Une erreur est survenue.";
toast.add({ title: "Échec de la déconnexion", description: message, color: "error" });
}
}
return { loginFields, onLoginSubmit, onLogoutClick };
}

View File

@@ -1,48 +0,0 @@
import type { FormSubmitEvent } from "@nuxt/ui";
import * as z from "zod";
const loginSchema = z.object({
email: z.email("Courriel invalide"),
password: z.string("Veuillez saisir votre mot de passe"),
});
type LoginSchema = z.infer<typeof loginSchema>;
const loginFields = [
{
name: "email",
type: "text" as const,
label: "Courriel",
placeholder: "Entrez votre courriel",
required: true,
}, {
name: "password",
label: "Mot de passe",
type: "password" as const,
placeholder: "Entrez votre mot de passe",
required: true,
},
];
export function useLogin() {
const toast = useToast();
const redirect = useRoute().query.redirect as string || "/";
const router = useRouter();
const { fetch: refreshUserSession } = useUserSession();
async function onLoginSubmit({ data }: FormSubmitEvent<LoginSchema>) {
try {
const result = await $fetch<{ success: boolean; message?: string }>("/api/login", { method: "POST", body: data });
if (!result.success) {
throw new Error(result.message || "Une erreur est survenue.");
}
await router.push(redirect);
await refreshUserSession();
}
catch (error) {
const message = error instanceof Error ? error.message : "Une erreur est survenue.";
toast.add({ title: "Échec de la connexion", description: message, color: "error" });
}
}
return { loginSchema, loginFields, onLoginSubmit };
}

View File

@@ -1,23 +0,0 @@
export function useLogout() {
const toast = useToast();
const redirect = useRoute().query.redirect as string || "/";
const router = useRouter();
const { fetch: refreshUserSession } = useUserSession();
async function onLogoutClick() {
try {
const result = await $fetch("/api/logout", { method: "POST" });
if (!result.success) {
throw new Error("Une erreur est survenue.");
}
await router.push(redirect);
await refreshUserSession();
}
catch (error) {
const message = error instanceof Error ? error.message : "Une erreur est survenue.";
toast.add({ title: "Échec de la déconnexion", description: message, color: "error" });
}
}
return { onLogoutClick };
}

View File

@@ -0,0 +1,3 @@
export function useMemberArea() {
return {};
}

View File

@@ -0,0 +1,3 @@
export function useMemberSignup() {
return {};
}

View File

@@ -1,19 +0,0 @@
fragment MenuItem on MenuItem {
id
label
to: path
target
}
query menuItems($location: MenuLocationEnum!) {
menuItems(where: {location: $location, parentDatabaseId: 0}) {
nodes {
...MenuItem
childItems {
nodes {
...MenuItem
}
}
}
}
}

View File

@@ -1,31 +0,0 @@
query nodeByUri($uri: String!) {
nodeByUri(uri: $uri) {
__typename
id
breadcrumbs {
label
to
}
... on Page {
...ThePage
}
... on Post {
...TheArticle
}
... on Event {
...TheEvent
}
... on Location {
...TheLocation
}
... on Membership {
...TheMembership
}
... on Project {
...TheProject
}
... on Resource {
...TheResource
}
}
}

View File

@@ -1,21 +1,5 @@
import type {
ThePageFragment,
TheArticleFragment,
TheEventFragment,
TheLocationFragment,
TheMembershipFragment,
TheProjectFragment,
TheResourceFragment,
} from "#graphql-operations";
import {
ThePage,
TheArticle,
TheEvent,
TheLocation,
TheMembership,
TheProject,
TheResource,
} from "#components";
import type { ThePageFragment, TheArticleFragment, TheEventFragment, TheLocationFragment, TheMembershipFragment, TheProjectFragment, TheResourceFragment } from "#graphql-operations";
import { ThePage, TheArticle, TheEvent, TheLocation, TheMembership, TheProject, TheResource } from "#components";
export async function useNodeByUri() {
const route = useRoute();

View File

@@ -1,13 +0,0 @@
fragment SiteOptions on GroupCcat {
profiles {
url
}
}
query siteOptions {
siteOptions {
groupCcat {
...SiteOptions
}
}
}