From c02c47efcb00782feb1461534923023a711d4f15 Mon Sep 17 00:00:00 2001 From: sowgro Date: Sun, 2 Mar 2025 11:22:48 -0500 Subject: First attempt at an authentication system. --- ufund-ui/src/app/app.component.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'ufund-ui/src/app/app.component.ts') diff --git a/ufund-ui/src/app/app.component.ts b/ufund-ui/src/app/app.component.ts index 2dbf33c..a85d04b 100644 --- a/ufund-ui/src/app/app.component.ts +++ b/ufund-ui/src/app/app.component.ts @@ -1,4 +1,7 @@ -import { Component } from '@angular/core'; +import {Component, OnInit} from '@angular/core'; +import {UsersService} from './services/users.service'; +import {BehaviorSubject, Observable, Subject} from 'rxjs'; +import {User} from './models/User'; @Component({ selector: 'app-root', @@ -6,6 +9,18 @@ import { Component } from '@angular/core'; standalone: false, styleUrl: './app.component.css' }) -export class AppComponent { - title = 'ufund-ui'; +export class AppComponent implements OnInit { + // title = 'ufund-ui'; + currentUser$: BehaviorSubject = new BehaviorSubject("Logged out."); + + constructor( + private userService: UsersService + ) {} + + ngOnInit() { + this.userService.getCurrentUser().subscribe(r => { + this.currentUser$?.next("Logged in as " + r.username) + }) + } + } -- cgit v1.2.3 From 51f0322db803ed3baf1f24f18a6e7a83dab58a3b Mon Sep 17 00:00:00 2001 From: sowgro Date: Sat, 15 Mar 2025 17:28:01 -0400 Subject: Add login redirection --- ufund-ui/src/app/app.component.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'ufund-ui/src/app/app.component.ts') diff --git a/ufund-ui/src/app/app.component.ts b/ufund-ui/src/app/app.component.ts index a85d04b..6f4e1f5 100644 --- a/ufund-ui/src/app/app.component.ts +++ b/ufund-ui/src/app/app.component.ts @@ -1,7 +1,6 @@ import {Component, OnInit} from '@angular/core'; import {UsersService} from './services/users.service'; -import {BehaviorSubject, Observable, Subject} from 'rxjs'; -import {User} from './models/User'; +import {BehaviorSubject} from 'rxjs'; @Component({ selector: 'app-root', @@ -18,8 +17,11 @@ export class AppComponent implements OnInit { ) {} ngOnInit() { - this.userService.getCurrentUser().subscribe(r => { - this.currentUser$?.next("Logged in as " + r.username) + this.userService.getCurrentUserSubject().subscribe(r => { + this.currentUser$?.next(r + ? "Logged in as " + r.username + : "Logged out." + ) }) } -- cgit v1.2.3