fix(console): clear storage entry if org is unknown, use zitadel as storage prefix, prettier domain verification (#836)

* fix: intercept wrong org id, zitadel as prefix

* rm constructor

* lint interceptor

* improve verification dialog

* refactor domain verification i18n

* reference preview img
This commit is contained in:
Max Peintner
2020-10-21 11:26:58 +02:00
committed by GitHub
parent b3f68c8f48
commit efcac8e70a
10 changed files with 85 additions and 53 deletions
@@ -5,7 +5,8 @@ import { Org } from 'src/app/proto/generated/auth_pb';
import { StorageService } from '../storage.service';
const orgKey = 'x-zitadel-orgid';
const ORG_HEADER_KEY = 'x-zitadel-orgid';
const ORG_STORAGE_KEY = 'organization';
@Injectable({ providedIn: 'root' })
export class OrgInterceptor<TReq = unknown, TResp = unknown> implements UnaryInterceptor<TReq, TResp> {
constructor(private readonly storageService: StorageService) { }
@@ -13,14 +14,19 @@ export class OrgInterceptor<TReq = unknown, TResp = unknown> implements UnaryInt
public intercept(request: Request<TReq, TResp>, invoker: any): Promise<UnaryResponse<TReq, TResp>> {
const metadata = request.getMetadata();
const org: Org.AsObject | null = (this.storageService.getItem('organization'));
const org: Org.AsObject | null = (this.storageService.getItem(ORG_STORAGE_KEY));
if (org) {
metadata[orgKey] = `${org.id}`;
metadata[ORG_HEADER_KEY] = `${org.id}`;
}
return invoker(request).then((response: any) => {
return response;
}).catch((error: any) => {
if (error.code === 7 && error.message.startsWith('Organisation doesn\'t exist')) {
this.storageService.removeItem(ORG_STORAGE_KEY);
}
return Promise.reject(error);
});
}
}
+2 -2
View File
@@ -1,11 +1,11 @@
import { Injectable } from '@angular/core';
import { OAuthStorage } from 'angular-oauth2-oidc';
const STORAGE_PREFIX = 'zitadel';
@Injectable({
providedIn: 'root',
})
export class StorageService implements OAuthStorage {
private storage: Storage = window.sessionStorage;
@@ -28,7 +28,7 @@ export class StorageService implements OAuthStorage {
}
public getPrefixedKey(key: string): string {
return `caos:${key}`;
return `${STORAGE_PREFIX}:${key}`;
}
}