@dishantlangayan/sc-cli-core 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/auth/org-manager.js +9 -5
- package/package.json +1 -1
package/lib/auth/org-manager.js
CHANGED
|
@@ -45,17 +45,21 @@ export class OrgManager {
|
|
|
45
45
|
this.ensureInitialized();
|
|
46
46
|
// Validate organization
|
|
47
47
|
this.validateOrg(org);
|
|
48
|
-
// Check if
|
|
49
|
-
const existingByOrgId = this.storage.orgs.find((o) => o.orgId === org.orgId);
|
|
50
|
-
if (existingByOrgId) {
|
|
51
|
-
throw new OrgError(`Organization '${org.orgId}' already exists`, OrgErrorCode.ORG_ALREADY_EXISTS);
|
|
52
|
-
}
|
|
48
|
+
// Check if alias already exists (aliases must be globally unique)
|
|
53
49
|
if (org.alias) {
|
|
54
50
|
const existingByAlias = this.storage.orgs.find((o) => o.alias === org.alias);
|
|
55
51
|
if (existingByAlias) {
|
|
56
52
|
throw new OrgError(`Organization with alias '${org.alias}' already exists`, OrgErrorCode.ORG_ALREADY_EXISTS);
|
|
57
53
|
}
|
|
58
54
|
}
|
|
55
|
+
// If no alias provided, check if orgId already exists (maintain current behavior)
|
|
56
|
+
// If alias is provided, allow multiple tokens for the same orgId with different aliases
|
|
57
|
+
if (!org.alias) {
|
|
58
|
+
const existingByOrgId = this.storage.orgs.find((o) => o.orgId === org.orgId);
|
|
59
|
+
if (existingByOrgId) {
|
|
60
|
+
throw new OrgError(`Organization '${org.orgId}' already exists`, OrgErrorCode.ORG_ALREADY_EXISTS);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
59
63
|
// If this org is being set as default, unset any existing default
|
|
60
64
|
if (org.isDefault) {
|
|
61
65
|
this.unsetAllDefaults();
|