mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-05-14 15:01:44 +00:00
* fix: change auth/V3user to auth/user Signed-off-by: Andy Lee <andy.lee@suse.com> * refactor: extract to utils/auth.js Signed-off-by: Andy Lee <andy.lee@suse.com> --------- Signed-off-by: Andy Lee <andy.lee@suse.com>
32 lines
893 B
JavaScript
32 lines
893 B
JavaScript
/**
|
|
* Resolve the Harvester username from Vuex getters.
|
|
*
|
|
* Works with both `this.$store.getters` (in components) and
|
|
* `this.$rootGetters` (in Steve models).
|
|
*
|
|
* - In single-product (standalone Harvester) mode, always returns the
|
|
* default username (`admin`).
|
|
* - Otherwise, falls back to the authenticated user's `username` or `id`.
|
|
*/
|
|
export function getHarvesterUserName(getters, defaultUserName = 'admin') {
|
|
const isSingleProduct = getters?.['isSingleProduct'];
|
|
|
|
if (isSingleProduct) {
|
|
return defaultUserName;
|
|
}
|
|
|
|
const user = getHarvesterUser(getters);
|
|
|
|
return user?.username || user?.id || defaultUserName;
|
|
}
|
|
|
|
/**
|
|
* Return the authenticated user object from Vuex getters.
|
|
*
|
|
* Works with both `this.$store.getters` (in components) and
|
|
* `this.$rootGetters` (in Steve models).
|
|
*/
|
|
export function getHarvesterUser(getters) {
|
|
return getters?.['auth/user'];
|
|
}
|