Files
teamwallet/myteamwallet_frontend_modern/src/app/app.ts
Bastian Wagner 6bea4f766a first commit
2026-07-31 21:02:47 +02:00

32 lines
819 B
TypeScript

import { Component, inject } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { AuthApi } from './core/auth/auth-api';
import { AuthStore } from './core/auth/auth-store';
@Component({
selector: 'app-root',
imports: [RouterOutlet],
templateUrl: './app.html',
styleUrl: './app.scss',
})
export class App {
private readonly authApi = inject(AuthApi);
private readonly authStore = inject(AuthStore);
constructor() {
if (this.authStore.token()) {
this.authApi.me().subscribe({
next: (response) => {
const { token, ...user } = response;
if (token) {
this.authStore.setSession(token, user);
} else {
this.authStore.updateUser(user);
}
},
error: () => undefined,
});
}
}
}