Browse Source

add tenant not found token

pull/17569/head
Mahmut Gundogdu 3 years ago
parent
commit
d2fb511415
  1. 3
      npm/ng-packs/packages/core/src/lib/proxy/pages/abp/multi-tenancy/abp-tenant.service.ts
  2. 3
      npm/ng-packs/packages/core/src/lib/tokens/tenant-not-found-by-name.ts
  3. 20
      npm/ng-packs/packages/core/src/lib/utils/multi-tenancy-utils.ts
  4. 6
      npm/ng-packs/packages/oauth/src/lib/services/oauth.service.ts

3
npm/ng-packs/packages/core/src/lib/proxy/pages/abp/multi-tenancy/abp-tenant.service.ts

@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { RestService } from '../../../../services/rest.service';
import type { FindTenantResultDto } from '../../../volo/abp/asp-net-core/mvc/multi-tenancy/models';
import { tap } from 'rxjs';
@Injectable({
providedIn: 'root',
@ -24,7 +25,7 @@ export class AbpTenantService {
url: `/api/abp/multi-tenancy/tenants/by-name/${name}`,
},
{ apiName: this.apiName },
);
).pipe(tap((res) => console.log(res)));
constructor(private restService: RestService) {}
}

3
npm/ng-packs/packages/core/src/lib/tokens/tenant-not-found-by-name.ts

@ -0,0 +1,3 @@
import { InjectionToken } from "@angular/core";
export const TENANT_NOT_FOUND_BY_NAME = new InjectionToken<string>('TENANT_NOT_FOUND_BY_NAME');

20
npm/ng-packs/packages/core/src/lib/utils/multi-tenancy-utils.ts

@ -8,6 +8,7 @@ import { FindTenantResultDto } from '../proxy/volo/abp/asp-net-core/mvc/multi-te
import { EnvironmentService } from '../services/environment.service';
import { MultiTenancyService } from '../services/multi-tenancy.service';
import { createTokenParser } from './string-utils';
import { firstValueFrom } from 'rxjs';
const tenancyPlaceholder = '{0}';
@ -24,6 +25,7 @@ function getCurrentTenancyNameFromUrl(tenantKey: string) {
return urlParams.get(tenantKey);
}
export async function parseTenantFromUrl(injector: Injector) {
const environmentService = injector.get(EnvironmentService);
const multiTenancyService = injector.get(MultiTenancyService);
@ -49,16 +51,26 @@ export async function parseTenantFromUrl(injector: Injector) {
};
if (tenancyName) {
debugger
/**
* We have to replace tenant name within the urls from environment,
* because the code below will make a http request to find information about the domain tenant.
* Before this request takes place, we need to replace placeholders aka "{0}".
*/
replaceTenantNameWithinEnvironment(injector, tenancyName);
return multiTenancyService
.setTenantByName(tenancyName)
.pipe(tap(setEnvironmentWithDomainTenant))
.toPromise();
const tenant$ = multiTenancyService
.setTenantByName(tenancyName)
.pipe(tap(setEnvironmentWithDomainTenant))
try {
const result = await firstValueFrom(tenant$)
return result;
}
catch (error) {
console.log(error)
debugger
}
} else {
/**
* If there is no tenant, we still have to clean up {0}. from baseUrl to avoid incorrect http requests.

6
npm/ng-packs/packages/oauth/src/lib/services/oauth.service.ts

@ -1,6 +1,6 @@
import { Injectable, Injector } from '@angular/core';
import { Params } from '@angular/router';
import { from, Observable, lastValueFrom } from 'rxjs';
import { from, Observable, lastValueFrom, EMPTY } from 'rxjs';
import { filter, map, switchMap, take, tap } from 'rxjs/operators';
import { AbpAuthResponse, IAuthService, LoginParams } from '@abp/ng.core';
import { AuthFlowStrategy } from '../strategies';
@ -44,6 +44,10 @@ export class AbpOAuthService implements IAuthService {
}
logout(queryParams?: Params): Observable<any> {
if(!this.strategy){
return EMPTY
}
return this.strategy.logout(queryParams);
}

Loading…
Cancel
Save