diff --git a/CONFIGURATION.md b/config/CONFIGURATION.md similarity index 81% rename from CONFIGURATION.md rename to config/CONFIGURATION.md index c6b85dc..2c35d71 100644 --- a/CONFIGURATION.md +++ b/config/CONFIGURATION.md @@ -7,6 +7,8 @@ site: # Informations du site theme: # Apparence +authentication: + # Authentification (optionnel) sections: # Liste des sections et liens ``` @@ -46,6 +48,24 @@ theme: background: "gradient" ``` +## `authentication` + +Configuration optionnelle pour l'authentification via un reverse proxy (Authelia, Authentik, etc.). + +| Champ | Requis | Type | Défaut | Description | +|---|---|---|---|---| +| `logout_url` | Oui | chaîne (URL) | — | URL de déconnexion (ex: `"https://auth.example.com/logout"`) | +| `header_format` | Non | chaîne | `"Remote-User"` | Nom de l'en-tête HTTP indiquant que l'utilisateur est connecté | +| `username` | Non | chaîne | — | Nom de l'en-tête HTTP contenant le nom d'utilisateur (ex: `"Remote-User"`). Affiche le nom dans le header quand renseigné. | + +Quand l'en-tête défini par `header_format` est présent dans la requête, un bouton de déconnexion apparaît à droite du bouton thème. + +```yaml +authentication: + logout_url: "https://auth.example.com/logout" + header_format: "Remote-User" +``` + ## `sections` Tableau de sections. Chaque section contient : @@ -124,6 +144,10 @@ theme: accent: "#8b5cf6" background: "gradient" +authentication: + logout_url: "https://auth.example.com/logout" + header_format: "Remote-User" + sections: - id: "services" title: "Services" diff --git a/config/dashboard.yml b/config/dashboard.yml index 819e1b6..028e9af 100644 --- a/config/dashboard.yml +++ b/config/dashboard.yml @@ -1,7 +1,8 @@ site: name: "Soch Family" - title: "Les applications de la famille" - #logoUrl: "" + title: " " + #title: "Les applications de la famille" + logoUrl: "https://immich.socheleau.fr/api/assets/e010423f-ca95-45a4-a9ee-9bb1a5a48688/thumbnail?slug=us_6&size=preview&c=IhgKJYiHg4ZfhXh6h5aJp5eAdQlJ&edited=true" #description: "Accès rapide à nos services" showFooter: false @@ -10,10 +11,16 @@ theme: accent: "#8b5cf6" background: "gradient" +authentication: + logout_url: "https://auth.socheleau.fr/logout" + header_format: "Remote-User" + username: "Remote-User" + sections: - id: "global" title: "Global" description: "Services accessibles à toute la famille" + cardLayout: "horizontal" links: - id: "nextcloud" name: "Nextcloud" diff --git a/src/app/page.tsx b/src/app/page.tsx index 49ff2f8..351ccf8 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,3 +1,4 @@ +import { headers } from "next/headers" import { getConfig } from "@/lib/config" import { Dashboard } from "@/components/dashboard/Dashboard" import { ErrorDisplay } from "@/components/ui/ErrorDisplay" @@ -18,12 +19,25 @@ function getConfigResult() { } } -export default function Home() { +export default async function Home() { const result = getConfigResult() if (!result.ok) { return } - return + const { config } = result + const authHeader = config.authentication?.header_format ?? "Remote-User" + const usernameHeader = config.authentication?.username + const headersList = await headers() + const isAuthenticated = config.authentication != null && headersList.has(authHeader) + const username = isAuthenticated && usernameHeader ? headersList.get(usernameHeader) ?? null : null + + return ( + + ) } diff --git a/src/components/dashboard/Dashboard.tsx b/src/components/dashboard/Dashboard.tsx index bea442b..0acb7fe 100644 --- a/src/components/dashboard/Dashboard.tsx +++ b/src/components/dashboard/Dashboard.tsx @@ -4,12 +4,20 @@ import type { DashboardConfig } from "@/types/config" interface DashboardProps { config: DashboardConfig + isAuthenticated?: boolean + username?: string | null } -export function Dashboard({ config }: DashboardProps) { +export function Dashboard({ config, isAuthenticated = false, username = null }: DashboardProps) { return (
- +
{config.sections.map((section, index) => ( diff --git a/src/components/dashboard/DashboardHeader.tsx b/src/components/dashboard/DashboardHeader.tsx index 9337cc2..b357b18 100644 --- a/src/components/dashboard/DashboardHeader.tsx +++ b/src/components/dashboard/DashboardHeader.tsx @@ -1,14 +1,17 @@ "use client" import { useState, useEffect } from "react" -import type { SiteConfig } from "@/types/config" +import type { SiteConfig, AuthenticationConfig } from "@/types/config" interface DashboardHeaderProps { site: SiteConfig initialTheme: "dark" | "light" + authentication?: AuthenticationConfig + isAuthenticated?: boolean + username?: string | null } -export function DashboardHeader({ site, initialTheme }: DashboardHeaderProps) { +export function DashboardHeader({ site, initialTheme, authentication, isAuthenticated = false, username = null }: DashboardHeaderProps) { const [isLight, setIsLight] = useState(initialTheme === "light") useEffect(() => { @@ -47,10 +50,10 @@ export function DashboardHeader({ site, initialTheme }: DashboardHeaderProps) {
- {site.description && ( -

- {site.description} -

+ {isAuthenticated && username && ( + + {username} + )} + {isAuthenticated && authentication && ( + + + + )}
- {site.description && ( -

- {site.description} + {isAuthenticated && username && ( +

+ {username}

)} diff --git a/src/lib/validation.ts b/src/lib/validation.ts index 8b2c089..64543f0 100644 --- a/src/lib/validation.ts +++ b/src/lib/validation.ts @@ -39,6 +39,12 @@ export const siteSchema = z.object({ showFooter: z.boolean().optional().default(true), }) +export const authenticationSchema = z.object({ + logout_url: z.string().url("Invalid logout URL").min(1, "Logout URL is required"), + header_format: z.string().optional().default("Remote-User"), + username: z.string().optional(), +}) + export const dashboardConfigSchema = z.object({ site: siteSchema, theme: themeSchema.optional().default({ @@ -46,5 +52,6 @@ export const dashboardConfigSchema = z.object({ accent: "#8b5cf6", background: "gradient", }), + authentication: authenticationSchema.optional(), sections: z.array(sectionSchema).default([]), }) diff --git a/src/types/config.ts b/src/types/config.ts index d4c1151..ef2d241 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -32,8 +32,15 @@ export interface SectionConfig { links: LinkConfig[] } +export interface AuthenticationConfig { + logout_url: string + header_format?: string + username?: string +} + export interface DashboardConfig { site: SiteConfig theme: ThemeConfig + authentication?: AuthenticationConfig sections: SectionConfig[] }