UserStatus.jsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // ---------------------------------------------------------------------------
  2. // Folder: components/app-shell
  3. // File: UserStatus.jsx
  4. // Relative Path: components/app-shell/UserStatus.jsx
  5. // ---------------------------------------------------------------------------
  6. "use client";
  7. import React from "react";
  8. import { useAuth } from "@/components/auth/authContext";
  9. /**
  10. * UserStatus (RHL-020)
  11. *
  12. * Responsibilities:
  13. * - Display minimal session info in the TopNav.
  14. *
  15. * Data source:
  16. * - AuthContext (provided by components/auth/AuthProvider.jsx)
  17. *
  18. * Behavior:
  19. * - unknown (no provider): "Not loaded" (keeps SSR tests stable)
  20. * - loading: "Loading..."
  21. * - authenticated: show role + optional branchId
  22. * - unauthenticated: "Signed out" (should be rare because we redirect)
  23. * - error: "Error"
  24. */
  25. export default function UserStatus() {
  26. const { status, user } = useAuth();
  27. let text = "Not loaded";
  28. if (status === "loading") text = "Loading...";
  29. if (status === "authenticated" && user) {
  30. // We only have userId/role/branchId from /api/auth/me.
  31. // Keep this minimal and non-personal.
  32. text = user.branchId ? `${user.role} (${user.branchId})` : `${user.role}`;
  33. }
  34. if (status === "unauthenticated") text = "Signed out";
  35. if (status === "error") text = "Error";
  36. return (
  37. <div className="hidden items-center gap-2 md:flex">
  38. <span className="text-xs text-muted-foreground">User:</span>
  39. <span className="text-xs">{text}</span>
  40. </div>
  41. );
  42. }