| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- "use client";
- import React from "react";
- import { RefreshCw } from "lucide-react";
- import { useAuth } from "@/components/auth/authContext";
- import { Button } from "@/components/ui/button";
- import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert";
- import {
- Card,
- CardHeader,
- CardTitle,
- CardDescription,
- CardContent,
- CardFooter,
- } from "@/components/ui/card";
- export default function AuthGate({ children }) {
- const { status, error, retry } = useAuth();
- const canRetry = typeof retry === "function";
- if (status === "authenticated") {
- return children;
- }
- if (status === "error") {
- return (
- <Card>
- <CardHeader>
- <CardTitle>Sitzungsprüfung fehlgeschlagen</CardTitle>
- <CardDescription>
- Die Sitzung konnte nicht geprüft werden.
- </CardDescription>
- </CardHeader>
- <CardContent className="space-y-3">
- <Alert variant="destructive">
- <AlertTitle>Fehler</AlertTitle>
- <AlertDescription>
- {error ||
- "Bitte prüfen Sie Ihre Verbindung und versuchen Sie es erneut."}
- </AlertDescription>
- </Alert>
- </CardContent>
- <CardFooter className="flex flex-col gap-2 sm:flex-row sm:justify-end">
- <Button
- type="button"
- variant="outline"
- onClick={() => {
- if (canRetry) retry();
- else window.location.reload();
- }}
- >
- <RefreshCw className="h-4 w-4" />
- Erneut versuchen
- </Button>
- </CardFooter>
- </Card>
- );
- }
- // "unauthenticated" -> redirect happens in AuthProvider.
- // Keeping this message is fine because TopNav indicator is not shown in this state.
- if (status === "unauthenticated") {
- return (
- <Card>
- <CardHeader>
- <CardTitle>Weiterleitung</CardTitle>
- <CardDescription>
- Sie werden zum Login weitergeleitet.
- </CardDescription>
- </CardHeader>
- <CardContent>
- <p className="text-sm text-muted-foreground">Bitte warten…</p>
- </CardContent>
- </Card>
- );
- }
- // Default: loading (or unknown)
- // RHL-032:
- // Do not render a second "session checking" UI here.
- // The TopNav SessionIndicator is the single source of feedback.
- return null;
- }
|