mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-11 17:26:45 +02:00
- Nouveaux tokens (indigo/corail, statuts, plateformes) et mode sombre - Logo et favicon Social Flow redessinés - AppShell partagé : sidebar groupée (desktop) + barre de navigation basse (mobile) - Suppression des pages mobiles dupliquées et des composants morts - Tableau de bord, connexion, 404, calendrier, médiathèque, IA, statistiques Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ADkrVcVFTT14hbB148HYS
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
import { useLocation } from "wouter";
|
|
import { apiRequest, AUTH_MUTATION, queryClient } from "@/lib/queryClient";
|
|
import { useToast } from "@/hooks/use-toast";
|
|
|
|
export interface Session {
|
|
id: string;
|
|
username: string;
|
|
role: string;
|
|
}
|
|
|
|
/** Session courante (mise en cache par react-query, partagée par toute l'app). */
|
|
export function useSession() {
|
|
const query = useQuery<Session>({
|
|
queryKey: ["/api/auth/session"],
|
|
retry: false,
|
|
});
|
|
return { ...query, session: query.data, isAdmin: query.data?.role === "admin" };
|
|
}
|
|
|
|
export function useLogout() {
|
|
const [, setLocation] = useLocation();
|
|
const { toast } = useToast();
|
|
return useMutation({
|
|
mutationKey: [AUTH_MUTATION, "logout"],
|
|
mutationFn: async () => {
|
|
const res = await apiRequest("POST", "/api/auth/logout", {});
|
|
return await res.json();
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.clear();
|
|
setLocation("/login");
|
|
toast({ title: "Déconnecté", description: "À bientôt !" });
|
|
},
|
|
});
|
|
}
|