Andy Lee 6fdd1e3954
fix: change auth/V3user to auth/user (#824)
* 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>
2026-04-22 15:39:24 +08:00

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'];
}