Skip to content

Commit 3276729

Browse files
fix: correct user initials display when authentication is enabled
2 parents f05f57f + bcdb3d8 commit 3276729

File tree

2 files changed

+20
-37
lines changed

2 files changed

+20
-37
lines changed

content-gen/src/app/frontend/src/App.tsx

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,11 @@ import { ChatHistory } from './components/ChatHistory';
1717
import type { ChatMessage, CreativeBrief, Product, GeneratedContent } from './types';
1818
import ContosoLogo from './styles/images/contoso.svg';
1919

20-
interface UserInfo {
21-
user_principal_id: string;
22-
user_name: string;
23-
auth_provider: string;
24-
is_authenticated: boolean;
25-
}
26-
2720

2821
function App() {
2922
const [conversationId, setConversationId] = useState<string>(() => uuidv4());
3023
const [userId, setUserId] = useState<string>('');
24+
const [userName, setUserName] = useState<string>('');
3125
const [messages, setMessages] = useState<ChatMessage[]>([]);
3226
const [isLoading, setIsLoading] = useState(false);
3327
const [generationStatus, setGenerationStatus] = useState<string>('');
@@ -72,18 +66,32 @@ function App() {
7266
fetchConfig();
7367
}, []);
7468

75-
// Fetch current user on mount
69+
// Fetch current user on mount - using /.auth/me (Azure App Service built-in auth endpoint)
7670
useEffect(() => {
7771
const fetchUser = async () => {
7872
try {
79-
const response = await fetch('/api/user');
73+
const response = await fetch('/.auth/me');
8074
if (response.ok) {
81-
const user: UserInfo = await response.json();
82-
setUserId(user.user_principal_id || 'anonymous');
75+
const payload = await response.json();
76+
77+
// Extract user ID from objectidentifier claim
78+
const userClaims = payload[0]?.user_claims || [];
79+
const objectIdClaim = userClaims.find(
80+
(claim: { typ: string; val: string }) =>
81+
claim.typ === 'http://schemas.microsoft.com/identity/claims/objectidentifier'
82+
);
83+
setUserId(objectIdClaim?.val || 'anonymous');
84+
85+
// Extract display name from 'name' claim
86+
const nameClaim = userClaims.find(
87+
(claim: { typ: string; val: string }) => claim.typ === 'name'
88+
);
89+
setUserName(nameClaim?.val || '');
8390
}
8491
} catch (err) {
8592
console.error('Error fetching user:', err);
8693
setUserId('anonymous');
94+
setUserName('');
8795
}
8896
};
8997
fetchUser();
@@ -725,17 +733,6 @@ function App() {
725733
}
726734
}, [confirmedBrief, selectedProducts, conversationId]);
727735

728-
// Get user initials for avatar
729-
const getUserInitials = () => {
730-
if (!userId) return 'U';
731-
// If we have a name, use first letter of first and last name
732-
const parts = userId.split('@')[0].split('.');
733-
if (parts.length >= 2) {
734-
return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();
735-
}
736-
return userId[0].toUpperCase();
737-
};
738-
739736
return (
740737
<div className="app-container">
741738
{/* Header */}
@@ -764,8 +761,7 @@ function App() {
764761
/>
765762
</Tooltip>
766763
<Avatar
767-
name={userId || 'User'}
768-
initials={getUserInitials()}
764+
name={userName || undefined}
769765
color="colorful"
770766
size={36}
771767
/>

content-gen/src/backend/app.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,6 @@ async def health_check():
7676
})
7777

7878

79-
# ==================== User Info Endpoint ====================
80-
81-
@app.route("/api/user", methods=["GET"])
82-
async def get_current_user():
83-
"""
84-
Get the current authenticated user info.
85-
86-
Returns user details from EasyAuth headers, or empty values if not authenticated.
87-
"""
88-
user = get_authenticated_user()
89-
return jsonify(user)
90-
91-
9279
# ==================== Chat Endpoints ====================
9380

9481
@app.route("/api/chat", methods=["POST"])

0 commit comments

Comments
 (0)