Skip to content

Commit bc65ed4

Browse files
authored
Fallback to username (email) if name is not available on msal account info (#1162)
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> This PR contains changes to default to MSAL username (default value: email) if name is undefined on the account. This was causing the experience to break for personal accounts as most don't have "Name" attribute defined. Fix for issue here: #912 ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] The PR follows SK Contribution Guidelines (https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) - [ ] The code follows the .NET coding conventions (https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions) verified with `dotnet format` - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
1 parent af03e00 commit bc65ed4

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

‎samples/apps/copilot-chat-app/webapp/src/components/chat/ChatRoom.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export const ChatRoom: React.FC = () => {
107107
const chatInput = {
108108
timestamp: new Date().getTime(),
109109
userId: account?.homeAccountId,
110-
userName: account?.name as string,
110+
userName: (account?.name ?? account?.username) as string,
111111
content: value,
112112
authorRole: AuthorRoles.User,
113113
};

‎samples/apps/copilot-chat-app/webapp/src/components/header/UserSettings.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ export const UserSettings: FC<IUserSettingsProps> = ({ setLoadingState }) => {
5151
{
5252
<Avatar
5353
className={classes.root}
54-
key={account?.name}
55-
name={account?.name}
54+
key={account?.name ?? account?.username}
55+
name={account?.name ?? account?.username}
5656
size={28}
5757
badge={{ status: 'available' }}
5858
/>
@@ -62,7 +62,7 @@ export const UserSettings: FC<IUserSettingsProps> = ({ setLoadingState }) => {
6262
<MenuList>
6363
<MenuItem className={classes.persona}>
6464
<Persona
65-
name={account?.name}
65+
name={account?.name ?? account?.username}
6666
secondaryText={account?.username}
6767
presence={{ status: 'available' }}
6868
avatar={{ color: 'colorful' }}

‎samples/apps/copilot-chat-app/webapp/src/libs/useChat.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const useChat = () => {
4444

4545
const loggedInUser: IChatUser = {
4646
id: account?.homeAccountId || '',
47-
fullName: account?.name || '',
47+
fullName: (account?.name ?? account?.username) || '',
4848
emailAddress: account?.username || '',
4949
photo: undefined, // TODO: Make call to Graph /me endpoint to load photo
5050
online: true,
@@ -62,7 +62,7 @@ export const useChat = () => {
6262
await chatService
6363
.createChatAsync(
6464
account?.homeAccountId!,
65-
account?.name!,
65+
account?.name ?? account?.username!,
6666
chatTitle,
6767
await AuthHelper.getSKaaSAccessToken(instance, inProgress),
6868
)
@@ -107,7 +107,7 @@ export const useChat = () => {
107107
},
108108
{
109109
key: 'userName',
110-
value: account?.name!,
110+
value: account?.name ?? account?.username!,
111111
},
112112
{
113113
key: 'chatId',

0 commit comments

Comments
 (0)