44 lines
990 B
TypeScript
44 lines
990 B
TypeScript
import { Component, inject, OnInit, OnDestroy } from '@angular/core';
|
|
import { CommonModule } from '@angular/common';
|
|
import { OsmAuth, OsmUser } from '../../services/osm-auth';
|
|
import { Subscription } from 'rxjs';
|
|
|
|
@Component({
|
|
selector: 'app-osm',
|
|
standalone: true,
|
|
imports: [CommonModule],
|
|
templateUrl: './osm.html',
|
|
styleUrl: './osm.scss'
|
|
})
|
|
export class Osm implements OnInit, OnDestroy {
|
|
private osmAuth = inject(OsmAuth);
|
|
private subscription?: Subscription;
|
|
|
|
currentUser: OsmUser | null = null;
|
|
isAuthenticated = false;
|
|
|
|
ngOnInit() {
|
|
this.subscription = this.osmAuth.currentUser$.subscribe(user => {
|
|
this.currentUser = user;
|
|
this.isAuthenticated = !!user;
|
|
});
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
if (this.subscription) {
|
|
this.subscription.unsubscribe();
|
|
}
|
|
}
|
|
|
|
login() {
|
|
this.osmAuth.initiateOAuthLogin();
|
|
}
|
|
|
|
logout() {
|
|
this.osmAuth.logout();
|
|
}
|
|
|
|
getUsername(): string {
|
|
return this.osmAuth.getUsername() || '';
|
|
}
|
|
}
|