UI: Added in refreshJwtToken updated in store Auth user when change property
This commit is contained in:
parent
6479a7ec76
commit
a8a787b94e
@ -27,7 +27,12 @@ import { defaultHttpOptions, defaultHttpOptionsFromConfig, RequestConfig } from
|
||||
import { UserService } from '../http/user.service';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { AppState } from '../core.state';
|
||||
import { ActionAuthAuthenticated, ActionAuthLoadUser, ActionAuthUnauthenticated } from './auth.actions';
|
||||
import {
|
||||
ActionAuthAuthenticated,
|
||||
ActionAuthLoadUser,
|
||||
ActionAuthUnauthenticated,
|
||||
ActionAuthUpdateAuthUser
|
||||
} from './auth.actions';
|
||||
import { getCurrentAuthState, getCurrentAuthUser } from './auth.selectors';
|
||||
import { Authority } from '@shared/models/authority.enum';
|
||||
import { ActionSettingsChangeLanguage } from '@app/core/settings/settings.actions';
|
||||
@ -480,6 +485,19 @@ export class AuthService {
|
||||
} else {
|
||||
this.updateAndValidateTokens(loginResponse.token, loginResponse.refreshToken, true);
|
||||
}
|
||||
const authUser = getCurrentAuthUser(this.store);
|
||||
const tokenData = this.jwtHelper.decodeToken(loginResponse.token);
|
||||
if (['sub', 'firstName', 'lastName'].some(value => authUser[value] !== tokenData[value])) {
|
||||
this.store.dispatch(new ActionAuthUpdateAuthUser({
|
||||
authUser: {
|
||||
...authUser, ...{
|
||||
sub: tokenData.sub,
|
||||
firstName: tokenData.firstName,
|
||||
lastName: tokenData.lastName,
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
this.refreshTokenSubject.next(loginResponse);
|
||||
this.refreshTokenSubject.complete();
|
||||
this.refreshTokenSubject = null;
|
||||
|
||||
@ -23,7 +23,7 @@ import { Store } from '@ngrx/store';
|
||||
import { AppState } from '@core/core.state';
|
||||
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
|
||||
import { HasConfirmForm } from '@core/guards/confirm-on-exit.guard';
|
||||
import { ActionAuthUpdateAuthUser, ActionAuthUpdateUserDetails } from '@core/auth/auth.actions';
|
||||
import { ActionAuthUpdateUserDetails } from '@core/auth/auth.actions';
|
||||
import { environment as env } from '@env/environment';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { ActionSettingsChangeLanguage } from '@core/settings/settings.actions';
|
||||
@ -95,11 +95,6 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir
|
||||
id: user.id,
|
||||
lastName: user.lastName,
|
||||
} }));
|
||||
this.store.dispatch(new ActionAuthUpdateAuthUser({ authUser: {...this.authUser, ...{
|
||||
sub: user.email,
|
||||
firstName: user.firstName,
|
||||
lastName: user.lastName,
|
||||
}}}));
|
||||
this.store.dispatch(new ActionSettingsChangeLanguage({ userLang: user.additionalInfo.lang }));
|
||||
this.authService.refreshJwtToken(false);
|
||||
}
|
||||
|
||||
@ -47,8 +47,8 @@ export interface AuthUser {
|
||||
sub: string;
|
||||
scopes: string[];
|
||||
userId: string;
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
enabled: boolean;
|
||||
tenantId: string;
|
||||
customerId: string;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user