fix: 🐛 OIDC authentications not properly showing username (#2930)

* fix: 🐛 properly show username for oidc auth method in user menu

* test: 💍 fix admin ui tests

* test: 💍 fix desktop ui tests

* refactor: 💡 admin to not store username in authenticated object

* refactor: 💡 use getter in app controller

* test: 💍 POC for how we could update our tests to use auth account

* refactor: 💡 remove unused service

* test: 💍 fix all tests in ui/admin

* test: 💍 revert one change

* refactor: 💡 update ui/desktop w/ feedback + fix tests

* refactor: 💡 add in error handling

* refactor: 💡 cleanup unused service

* test: 💍 fix e2e test selector

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-17231
This commit is contained in:
Lisbet Alvarez authored and GitHub committed 2025-10-30 12:49:30 -07:00
1 parent 838bc37243
commit 72f7c8a92d
195 files changed
+720 -1112

No files matched your search

+2
View File
@@ -75,6 +75,8 @@ export default class ApplicationRoute extends Route {
if (userId && hostUrl) {
await this.sqlite.setup(formatDbName(userId, hostUrl));
}
await this.session.loadAuthenticatedAccount();
}
}
+27
View File
@@ -5,11 +5,15 @@
import BaseSessionService from 'ember-simple-auth/services/session';
import { service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { formatDbName } from 'api/services/sqlite';
export default class SessionService extends BaseSessionService {
@service sqlite;
@service('browser/window') window;
@service store;
@tracked username;
/**
* Extend ember simple auth's handleAuthentication method
@@ -22,8 +26,31 @@ export default class SessionService extends BaseSessionService {
await this.sqlite.setup(formatDbName(userId, hostUrl));
}
await this.loadAuthenticatedAccount();
// We let ember-simple-auth handle transitioning back to the index after authentication.
// This route can be configured in our environment config.
super.handleAuthentication(...arguments);
}
/**
* Loads account used to authenticate so that it can be used to display
* the authenticated username.
*/
async loadAuthenticatedAccount() {
if (this.data?.authenticated?.account_id) {
try {
const account = await this.store.findRecord(
'account',
this.data.authenticated.account_id,
);
this.username = account.accountName;
} catch (e) {
// We are purposefully ignoring errors since loading the
// authenticated account should not block a user because
// account information is for populating a username.
console.error(e);
}
}
}
}
+15
View File
@@ -1025,3 +1025,18 @@
.injected-app-credential-alert {
margin-bottom: 1rem;
}
// User menu dropdown in global side nav
.user-menu-dropdown {
max-width: 125px;
&__toggle-button {
width: 100%;
.hds-dropdown-toggle-button__text {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
}
+61 -29
View File
@@ -71,41 +71,73 @@
</Hds::Dropdown>
{{/if}}
<Hds::Dropdown
@enableCollisionDetection={{true}}
data-test-side-nav-user-dropdown
as |dd|
>
{{#if this.session.data.authenticated.username}}
{{#if this.session.username}}
<Hds::Dropdown
@enableCollisionDetection={{true}}
class='user-menu-dropdown'
data-test-side-nav-user-dropdown
as |dd|
>
<dd.ToggleButton
@icon='user'
@text={{this.session.data.authenticated.username}}
@text={{this.session.username}}
{{hds-tooltip this.session.username}}
class='user-menu-dropdown__toggle-button'
/>
{{else}}
<dd.Title @text={{t 'titles.authenticated'}} />
<dd.Description @text={{this.session.username}} />
<dd.Separator />
<dd.Interactive @route='account.change-password'>{{t
'actions.change-password'
}}</dd.Interactive>
<dd.Separator />
<dd.Interactive {{on 'click' this.invalidateSession}}>{{t
'actions.deauthenticate'
}}</dd.Interactive>
<dd.Separator />
<dd.Title @text={{t 'actions.toggle-color-theme'}} />
{{#each this.themes as |theme|}}
<dd.Radio
@value={{theme.value}}
checked={{eq this.session.data.theme theme.value}}
{{on 'change' (fn this.toggleTheme theme.value)}}
>
{{t (concat 'themes.' theme.label)}}
</dd.Radio>
{{/each}}
</Hds::Dropdown>
{{else}}
<Hds::Dropdown
@enableCollisionDetection={{true}}
data-test-side-nav-user-dropdown
as |dd|
>
<dd.ToggleIcon @icon='user' @text={{t 'titles.user-menu'}} />
{{/if}}
<dd.Interactive @route='account.change-password'>{{t
'actions.change-password'
}}</dd.Interactive>
<dd.Separator />
<dd.Interactive @route='account.change-password'>{{t
'actions.change-password'
}}</dd.Interactive>
<dd.Separator />
<dd.Interactive {{on 'click' this.invalidateSession}}>{{t
'actions.deauthenticate'
}}</dd.Interactive>
<dd.Separator />
<dd.Interactive {{on 'click' this.invalidateSession}}>{{t
'actions.deauthenticate'
}}</dd.Interactive>
<dd.Separator />
<dd.Title @text={{t 'actions.toggle-color-theme'}} />
{{#each this.themes as |theme|}}
<dd.Radio
@value={{theme.value}}
checked={{eq this.session.data.theme theme.value}}
{{on 'change' (fn this.toggleTheme theme.value)}}
>
{{t (concat 'themes.' theme.label)}}
</dd.Radio>
{{/each}}
</Hds::Dropdown>
<dd.Title @text={{t 'actions.toggle-color-theme'}} />
{{#each this.themes as |theme|}}
<dd.Radio
@value={{theme.value}}
checked={{eq this.session.data.theme theme.value}}
{{on 'change' (fn this.toggleTheme theme.value)}}
>
{{t (concat 'themes.' theme.label)}}
</dd.Radio>
{{/each}}
</Hds::Dropdown>
{{/if}}
</:actions>
</Hds::SideNav::Header>
</:header>