Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

74 lines
1.9 KiB

/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
import {
ApiUrlConfig,
AuthService,
fadeAnimation,
ModalModel,
StatefulComponent,
UIState
} from '@app/shared';
interface State {
// The display name of the user.
profileDisplayName: string;
// The id of the user.
profileId: string;
// The email address of the user.
profileEmail: string;
// The url to the user profile.
profileUrl: string;
}
@Component({
selector: 'sqx-profile-menu',
styleUrls: ['./profile-menu.component.scss'],
templateUrl: './profile-menu.component.html',
animations: [
fadeAnimation
],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ProfileMenuComponent extends StatefulComponent<State> implements OnInit {
public modalMenu = new ModalModel();
constructor(changeDetector: ChangeDetectorRef, apiUrl: ApiUrlConfig,
public readonly uiState: UIState,
private readonly authService: AuthService
) {
super(changeDetector, {
profileDisplayName: '',
profileEmail: '',
profileId: '',
profileUrl: apiUrl.buildUrl('/identity-server/account/profile')
});
}
public ngOnInit() {
this.own(
this.authService.userChanges
.subscribe(user => {
if (user) {
const profileId = user.id;
const profileEmail = user.email;
const profileDisplayName = user.displayName;
this.next(s => ({ ...s, profileId, profileEmail, profileDisplayName }));
}
}));
}
public logout() {
this.authService.logoutRedirect();
}
}