From 3c924899ca6e5b797bd6536420f75efb61981787 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Thu, 28 Nov 2019 10:43:46 +0300 Subject: [PATCH] fix(account): add header parameter to fetchTokenUsingPasswordFlow method --- .../components/register/register.component.ts | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/npm/ng-packs/packages/account/src/lib/components/register/register.component.ts b/npm/ng-packs/packages/account/src/lib/components/register/register.component.ts index e01287e1cb..fad7ae5fc7 100644 --- a/npm/ng-packs/packages/account/src/lib/components/register/register.component.ts +++ b/npm/ng-packs/packages/account/src/lib/components/register/register.component.ts @@ -1,4 +1,4 @@ -import { ConfigState, GetAppConfiguration, ABP } from '@abp/ng.core'; +import { ConfigState, GetAppConfiguration, ABP, SessionState } from '@abp/ng.core'; import { ToasterService } from '@abp/ng.theme.shared'; import { Component, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; @@ -11,6 +11,7 @@ import snq from 'snq'; import { RegisterRequest } from '../../models'; import { AccountService } from '../../services/account.service'; import { PasswordRules, validatePassword } from '@ngx-validate/core'; +import { HttpHeaders } from '@angular/common/http'; const { maxLength, minLength, required, email } = Validators; @Component({ @@ -29,7 +30,9 @@ export class RegisterComponent implements OnInit { private store: Store, private toasterService: ToasterService, ) { - this.oauthService.configure(this.store.selectSnapshot(ConfigState.getOne('environment')).oAuthConfig); + this.oauthService.configure( + this.store.selectSnapshot(ConfigState.getOne('environment')).oAuthConfig, + ); this.oauthService.loadDiscoveryDocument(); } @@ -62,7 +65,10 @@ export class RegisterComponent implements OnInit { this.form = this.fb.group({ username: ['', [required, maxLength(255)]], - password: ['', [required, validatePassword(passwordRulesArr), minLength(requiredLength), maxLength(32)]], + password: [ + '', + [required, validatePassword(passwordRulesArr), minLength(requiredLength), maxLength(32)], + ], email: ['', [required, email]], }); } @@ -79,10 +85,22 @@ export class RegisterComponent implements OnInit { appName: 'Angular', } as RegisterRequest; + const tenant = this.store.selectSnapshot(SessionState.getTenant); + this.accountService .register(newUser) .pipe( - switchMap(() => from(this.oauthService.fetchTokenUsingPasswordFlow(newUser.userName, newUser.password))), + switchMap(() => + from( + this.oauthService.fetchTokenUsingPasswordFlow( + newUser.userName, + newUser.password, + new HttpHeaders({ + ...(tenant && tenant.id && { __tenant: tenant.id }), + }), + ), + ), + ), switchMap(() => this.store.dispatch(new GetAppConfiguration())), tap(() => this.store.dispatch(new Navigate(['/']))), take(1),