diff --git a/matsen-tool/src/app/_helpers/jwt.interceptor.ts b/matsen-tool/src/app/_helpers/jwt.interceptor.ts index 85a2550..b8005ed 100644 --- a/matsen-tool/src/app/_helpers/jwt.interceptor.ts +++ b/matsen-tool/src/app/_helpers/jwt.interceptor.ts @@ -10,6 +10,7 @@ export class JwtInterceptor implements HttpInterceptor { constructor(private accountService: AccountService) { } intercept(request: HttpRequest, next: HttpHandler): Observable> { + console.log('intercept'); // add auth header with jwt if user is logged in and request is to the api url const user = this.accountService.userValue; const isLoggedIn = user && user.token; diff --git a/matsen-tool/src/app/_services/account.service.ts b/matsen-tool/src/app/_services/account.service.ts index e1fb715..5af2a36 100644 --- a/matsen-tool/src/app/_services/account.service.ts +++ b/matsen-tool/src/app/_services/account.service.ts @@ -24,8 +24,8 @@ export class AccountService { return this.userSubject.value; } - login(username: string, password: string) { - return this.http.post(`${environment.apiUrl}/login`, { username, password }) + login(email: string, password: string) { + return this.http.post(`${environment.basePath}/auth`, { email, password }) .pipe(map(user => { // store user details and jwt token in local storage to keep user logged in between page refreshes localStorage.setItem('user', JSON.stringify(user)); diff --git a/matsen-tool/src/app/app.component.html b/matsen-tool/src/app/app.component.html index b2409a6..970b494 100644 --- a/matsen-tool/src/app/app.component.html +++ b/matsen-tool/src/app/app.component.html @@ -7,14 +7,6 @@ - - - - - - - -
diff --git a/matsen-tool/src/app/app.component.ts b/matsen-tool/src/app/app.component.ts index 0d3cd93..b8b2901 100644 --- a/matsen-tool/src/app/app.component.ts +++ b/matsen-tool/src/app/app.component.ts @@ -1,36 +1,27 @@ import {Component, OnInit} from '@angular/core'; -import { AccountService } from './_services'; -import { User } from './_models'; +import {AccountService} from './_services'; +import {User} from './_models'; import {Subscription} from "rxjs"; import {PostJsonld, PostService} from "@app/core/api/v1"; @Component({ - selector: 'app-root', - templateUrl: 'app.component.html', - styleUrl: 'app.component.scss' + selector: 'app-root', + templateUrl: 'app.component.html', + styleUrl: 'app.component.scss' }) export class AppComponent implements OnInit { user?: User | null; - protected postSub: Subscription; - protected posts: Array; constructor(private postService: PostService, private accountService: AccountService) { this.accountService.user.subscribe(x => this.user = x); - this.postSub = new Subscription(); - this.posts = []; } - ngOnInit(): void { - this.postSub = this.postService.postsGetCollection().subscribe( - data => { - this.posts = data["hydra:member"]; - console.log(data); - } - ); + ngOnInit(): void { + + } - } logout() { this.accountService.logout(); } diff --git a/matsen-tool/src/app/app.module.ts b/matsen-tool/src/app/app.module.ts index 9758492..54b059e 100644 --- a/matsen-tool/src/app/app.module.ts +++ b/matsen-tool/src/app/app.module.ts @@ -1,26 +1,27 @@ -import { NgModule } from '@angular/core'; -import { BrowserModule } from '@angular/platform-browser'; -import { ReactiveFormsModule } from '@angular/forms'; -import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; +import {NgModule} from '@angular/core'; +import {BrowserModule} from '@angular/platform-browser'; +import {ReactiveFormsModule} from '@angular/forms'; +import {HttpClientModule, HTTP_INTERCEPTORS} from '@angular/common/http'; // used to create fake backend -import { fakeBackendProvider } from './_helpers'; +import {fakeBackendProvider} from './_helpers'; -import { AppRoutingModule } from './app-routing.module'; -import { JwtInterceptor, ErrorInterceptor } from './_helpers'; -import { AppComponent } from './app.component'; -import { AlertComponent } from './_components'; -import { HomeComponent } from './home'; +import {AppRoutingModule} from './app-routing.module'; +import {JwtInterceptor, ErrorInterceptor} from './_helpers'; +import {AppComponent} from './app.component'; +import {AlertComponent} from './_components'; +import {HomeComponent} from './home'; import {NgbModule} from "@ng-bootstrap/ng-bootstrap"; import {ApiModule, Configuration, ConfigurationParameters} from "@app/core/api/v1"; import {environment} from "@environments/environment"; import {MatCardModule} from "@angular/material/card"; export function apiConfigFactory(): Configuration { - const params: ConfigurationParameters = { - basePath: environment.basePath, - }; - return new Configuration(params); + const params: ConfigurationParameters = { + basePath: environment.basePath, + withCredentials: false + }; + return new Configuration(params); } @NgModule({ @@ -31,7 +32,7 @@ export function apiConfigFactory(): Configuration { HttpClientModule, NgbModule, AppRoutingModule, - MatCardModule + MatCardModule ], declarations: [ AppComponent, @@ -39,12 +40,13 @@ export function apiConfigFactory(): Configuration { HomeComponent ], providers: [ - { provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true }, - { provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true }, + {provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true}, + {provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true}, // provider used to create fake backend fakeBackendProvider ], bootstrap: [AppComponent] }) -export class AppModule { }; +export class AppModule { +}; diff --git a/matsen-tool/src/app/home/home.component.html b/matsen-tool/src/app/home/home.component.html index 4ce8b35..6e4e0fe 100644 --- a/matsen-tool/src/app/home/home.component.html +++ b/matsen-tool/src/app/home/home.component.html @@ -58,3 +58,10 @@
+
    +
  • Posts
  • +
  • +

    {{post.id}} - {{post.owner}}

    +

    {{post.message}}

    +
  • +
diff --git a/matsen-tool/src/app/home/home.component.ts b/matsen-tool/src/app/home/home.component.ts index 0b17bba..1bb5978 100644 --- a/matsen-tool/src/app/home/home.component.ts +++ b/matsen-tool/src/app/home/home.component.ts @@ -1,17 +1,33 @@ -import { Component } from '@angular/core'; +import {Component, OnInit} from '@angular/core'; import { User } from '@app/_models'; import { AccountService } from '@app/_services'; import {MatCardModule} from "@angular/material/card"; +import {Subscription} from "rxjs"; +import {PostJsonld, PostService} from "@app/core/api/v1"; @Component({ templateUrl: 'home.component.html', styleUrl: 'home.component.scss' }) -export class HomeComponent { +export class HomeComponent implements OnInit{ user: User | null; + protected postSub: Subscription; + protected posts: Array; - constructor(private accountService: AccountService) { + constructor(private accountService: AccountService, private postService: PostService) { this.user = this.accountService.userValue; + // this.accountService.user.subscribe(x => this.user = x); + this.postSub = new Subscription(); + this.posts = []; + } + + ngOnInit(): void { + this.postSub = this.postService.postsGetCollection().subscribe( + data => { + this.posts = data["hydra:member"]; + } + ); + } } diff --git a/matsen-tool/src/app/users/list.component.ts b/matsen-tool/src/app/users/list.component.ts index da57dad..ac03d48 100644 --- a/matsen-tool/src/app/users/list.component.ts +++ b/matsen-tool/src/app/users/list.component.ts @@ -12,16 +12,17 @@ export class ListComponent implements OnInit { protected users: Array; constructor(private userService: UserService) { - this.usersSub = new Subscription(); - this.users = []; + this.usersSub = new Subscription(); + this.users = []; + console.log('sdaaadsds'); } ngOnInit() { this.usersSub = this.userService.usersGetCollection().subscribe( data => { - - this.users = data["hydra:member"]; - console.log(data); + console.log('sdaaadsds2332232332'); + this.users = data["hydra:member"]; + console.log(data); } ); // this.accountService.getAll() diff --git a/matsen-tool/src/environments/environment.ts b/matsen-tool/src/environments/environment.ts index b4cff53..4a883d6 100644 --- a/matsen-tool/src/environments/environment.ts +++ b/matsen-tool/src/environments/environment.ts @@ -4,8 +4,8 @@ export const environment = { production: false, - apiUrl: 'https://matsen-tool-be.ddev.site:8443', - basePath: 'https://matsen-tool-be.ddev.site:8443' + basePath: 'https://matsen-tool-be.ddev.site:8443', + apiUrl: 'https://matsen-tool-be.ddev.site:8443/api' }; /*