mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-10-01 03:36:04 +08:00
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>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* 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'];
|
||||
}
|
||||
Reference in New Issue
Block a user