Skip to content

fix: fallback to user email when username is unset#237

Merged
tale merged 1 commit intotale:mainfrom
gabe565:fix-fallback-user-email
Jun 6, 2025
Merged

fix: fallback to user email when username is unset#237
tale merged 1 commit intotale:mainfrom
gabe565:fix-fallback-user-email

Conversation

@gabe565
Copy link
Contributor

@gabe565 gabe565 commented Jun 3, 2025

More recent versions of Headscale have changed username to be an optional field, causing the Machines page to show an empty field where the username would normally be displayed. This PR makes it fallback to displaying the email when this is the case.

I'm not very familiar with React, so let me know if there's a better way to do this. I'd love to be able to see which user manages a machine at a glance again!

Before

After

@0xlilim
Copy link

0xlilim commented Jun 4, 2025

I'm facing the same problem. This occurs if fetching the username via OIDC fails, leading to an inability to control users.

I previously submitted a patch to Headscale that would fall back to the default email address upon username fetching failure. However, it was closed, possibly due to concerns about complex ACL controls, and wasn't merged.
juanfont/headscale#2633

It would be fantastic if Headplane could offer a solution for this!

Copy link
Owner

@tale tale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall fine, just change all the logical ors (||) to use nullish coalescing operators instead (??).

@gabe565 gabe565 force-pushed the fix-fallback-user-email branch from 87b6cca to 71e0134 Compare June 5, 2025 02:34
@gabe565
Copy link
Contributor Author

gabe565 commented Jun 5, 2025

@tale Oh thanks, I didn't know that operator existed. Done!

@gabe565 gabe565 requested a review from tale June 5, 2025 03:40
@tale tale merged commit a298686 into tale:main Jun 6, 2025
2 of 3 checks passed
@gabe565
Copy link
Contributor Author

gabe565 commented Jun 20, 2025

@tale I was just testing v0.6.1-next in #256 and I noticed this isn't working correctly. I believe it's because nullish coalescing operators only use the fallback value when the first value is null or undefined, but when username is unset, it's an empty string. A logical or worked here since an empty string is falsy. Should I open another PR to change it to a logical or?

@gabe565 gabe565 deleted the fix-fallback-user-email branch June 20, 2025 23:24
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.

3 participants