Skip to content

Fix TypeError crash when token lacks upn and unique_name fields#15779

Draft
Copilot wants to merge 2 commits intodevfrom
copilot/fix-teamsapp-extend-error
Draft

Fix TypeError crash when token lacks upn and unique_name fields#15779
Copilot wants to merge 2 commits intodevfrom
copilot/fix-teamsapp-extend-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 23, 2026

When a user's token has neither upn nor unique_name fields, the telemetry code in loginWithBrowser and loginWithBroker crashes with TypeError: Cannot read properties of undefined (reading 'endsWith'), surfacing as an unexpected error during teamsAppExtendToM365.

Change

Added optional chaining (?.) before .endsWith() in both loginWithBrowser and loginWithBroker in packages/vscode-extension/src/commonlib/codeFlowLogin.ts:

// Before — throws if both upn and unique_name are undefined
[TelemetryProperty.Internal]: (
  (tokenJson as any).upn ?? (tokenJson as any).unique_name
).endsWith("@microsoft.com") ? "true" : "false",

// After — safely falls through to "false"
[TelemetryProperty.Internal]: (
  (tokenJson as any).upn ?? (tokenJson as any).unique_name
)?.endsWith("@microsoft.com") ? "true" : "false",

…hBrowser/loginWithBroker

Agent-Logs-Url: https://github.com/OfficeDev/microsoft-365-agents-toolkit/sessions/e38e2d8e-2f70-4b9f-8526-224f6c781ab3

Co-authored-by: HuihuiWu-Microsoft <73154171+HuihuiWu-Microsoft@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix unexpected error in teamsAppExtendToM365 task Fix TypeError crash when token lacks upn and unique_name fields Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug report: teamsAppExtendToM365.IJe

2 participants