diff --git a/backend/src/controllers/authController.ts b/backend/src/controllers/authController.ts
index 5fc95b7d..386148fe 100644
--- a/backend/src/controllers/authController.ts
+++ b/backend/src/controllers/authController.ts
@@ -319,6 +319,49 @@ export class AuthController {
);
}
+ /**
+ * GET /api/auth/session
+ * Returns the authenticated user's display identity and organization.
+ */
+ static async session(req: express.Request, res: express.Response) {
+ try {
+ const result = await query(
+ `SELECT
+ u.id,
+ u.email,
+ u.name,
+ u.wallet_address,
+ u.organization_id,
+ u.role,
+ o.name AS organization_name
+ FROM users u
+ LEFT JOIN organizations o ON o.id = u.organization_id
+ WHERE u.id = $1`,
+ [req.user!.id]
+ );
+
+ if (result.rows.length === 0) {
+ return res.status(404).json({ error: 'User not found' });
+ }
+
+ const user = result.rows[0];
+ return res.json({
+ user: {
+ id: user.id,
+ email: user.email ?? null,
+ name: user.name ?? null,
+ walletAddress: user.wallet_address ?? null,
+ organizationId: user.organization_id ?? null,
+ organizationName: user.organization_name ?? null,
+ role: user.role,
+ },
+ });
+ } catch (error) {
+ console.error('Session lookup failed:', error);
+ return res.status(500).json({ error: 'Internal server error' });
+ }
+ }
+
/**
* POST /api/auth/refresh
* Refreshes access token using a valid refresh token.
diff --git a/backend/src/routes/authRoutes.ts b/backend/src/routes/authRoutes.ts
index 16f75526..1183d365 100644
--- a/backend/src/routes/authRoutes.ts
+++ b/backend/src/routes/authRoutes.ts
@@ -10,6 +10,7 @@ const router = Router();
router.post('/login', AuthController.login);
router.post('/register', AuthController.register);
router.post('/refresh', AuthController.refresh);
+router.get('/session', authenticateJWT, AuthController.session);
router.post(
'/invitations',
diff --git a/frontend/src/components/AppNav.tsx b/frontend/src/components/AppNav.tsx
index ced8ef3b..b03e7017 100644
--- a/frontend/src/components/AppNav.tsx
+++ b/frontend/src/components/AppNav.tsx
@@ -13,18 +13,15 @@ import {
X,
BarChart2,
TrendingUp,
+ LogOut,
} from 'lucide-react';
import { Avatar } from './Avatar';
+import { useAuth } from '../providers/AuthProvider';
const AppNav: React.FC = () => {
const [mobileOpen, setMobileOpen] = useState(false);
- // Mock user data - replace with actual user context
- const currentUser = {
- email: 'user@example.com',
- name: 'John Doe',
- imageUrl: undefined,
- };
+ const { user, loading, logout } = useAuth();
const navLinks = (
<>
@@ -202,6 +199,49 @@ const AppNav: React.FC = () => {
>
);
+ const displayName = user?.name || user?.email || user?.walletAddress || '';
+ const displayDetail = user?.email || user?.walletAddress || '';
+
+ const renderUserProfile = (showDetails: boolean) =>
+ loading ? (
+
+ ) : user ? (
+
+
+
+
+
{displayName}
+
{displayDetail}
+
+
+
+
+ ) : (
+
+ Sign in
+
+ );
+
return (