| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- // ---------------------------------------------------------------------------
- // Folder: components/app-shell
- // File: UserStatus.jsx
- // Relative Path: components/app-shell/UserStatus.jsx
- // ---------------------------------------------------------------------------
- "use client";
- import React from "react";
- import { useAuth } from "@/components/auth/authContext";
- /**
- * UserStatus (RHL-020)
- *
- * Responsibilities:
- * - Display minimal session info in the TopNav.
- *
- * Data source:
- * - AuthContext (provided by components/auth/AuthProvider.jsx)
- *
- * Behavior:
- * - unknown (no provider): "Not loaded" (keeps SSR tests stable)
- * - loading: "Loading..."
- * - authenticated: show role + optional branchId
- * - unauthenticated: "Signed out" (should be rare because we redirect)
- * - error: "Error"
- */
- export default function UserStatus() {
- const { status, user } = useAuth();
- let text = "Not loaded";
- if (status === "loading") text = "Loading...";
- if (status === "authenticated" && user) {
- // We only have userId/role/branchId from /api/auth/me.
- // Keep this minimal and non-personal.
- text = user.branchId ? `${user.role} (${user.branchId})` : `${user.role}`;
- }
- if (status === "unauthenticated") text = "Signed out";
- if (status === "error") text = "Error";
- return (
- <div className="hidden items-center gap-2 md:flex">
- <span className="text-xs text-muted-foreground">User:</span>
- <span className="text-xs">{text}</span>
- </div>
- );
- }
|