generated from pascalmartineau/wp-skeleton
refactor: better project structure
All checks were successful
Deploy WordPress and Nuxt / deploy (push) Successful in 6m3s
All checks were successful
Deploy WordPress and Nuxt / deploy (push) Successful in 6m3s
This commit is contained in:
57
wp-content/themes/ccat/app/composables/useAuth.ts
Normal file
57
wp-content/themes/ccat/app/composables/useAuth.ts
Normal 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 };
|
||||
}
|
||||
@@ -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 };
|
||||
}
|
||||
@@ -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 };
|
||||
}
|
||||
3
wp-content/themes/ccat/app/composables/useMemberArea.ts
Normal file
3
wp-content/themes/ccat/app/composables/useMemberArea.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export function useMemberArea() {
|
||||
return {};
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export function useMemberSignup() {
|
||||
return {};
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
fragment SiteOptions on GroupCcat {
|
||||
profiles {
|
||||
url
|
||||
}
|
||||
}
|
||||
|
||||
query siteOptions {
|
||||
siteOptions {
|
||||
groupCcat {
|
||||
...SiteOptions
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user