oedb-backend/frontend/src/app/forms/osm/osm.ts

45 lines
990 B
TypeScript
Raw Normal View History

import { Component, inject, OnInit, OnDestroy } from '@angular/core';
import { CommonModule } from '@angular/common';
import { OsmAuth, OsmUser } from '../../services/osm-auth';
import { Subscription } from 'rxjs';
2025-10-03 11:56:55 +02:00
@Component({
selector: 'app-osm',
standalone: true,
imports: [CommonModule],
2025-10-03 11:56:55 +02:00
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;
2025-10-03 11:56:55 +02:00
ngOnInit() {
this.subscription = this.osmAuth.currentUser$.subscribe(user => {
this.currentUser = user;
this.isAuthenticated = !!user;
});
}
2025-10-03 14:00:35 +02:00
ngOnDestroy() {
if (this.subscription) {
this.subscription.unsubscribe();
}
2025-10-03 14:00:35 +02:00
}
login() {
this.osmAuth.initiateOAuthLogin();
}
logout() {
this.osmAuth.logout();
}
2025-10-03 14:00:35 +02:00
getUsername(): string {
return this.osmAuth.getUsername() || '';
2025-10-03 14:00:35 +02:00
}
2025-10-03 11:56:55 +02:00
}