Fix token storage
This commit is contained in:
parent
20f89155d0
commit
95a524dd04
@ -1,20 +1,29 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
|
import { TokenStorageService } from './token.service';
|
||||||
const API_URL = 'https://aktienbot.flokaiser.com/api/';
|
const API_URL = 'https://aktienbot.flokaiser.com/api/';
|
||||||
const httpOptions = {
|
|
||||||
headers: new HttpHeaders({
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
Authorization: 'Bearer',
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class DataService {
|
export class DataService {
|
||||||
constructor(private http: HttpClient) {}
|
constructor(
|
||||||
getPublicContent(): Observable<any> {
|
private http: HttpClient,
|
||||||
return this.http.get(API_URL + 'portfolio', { responseType: 'text' });
|
private tokenStorage: TokenStorageService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
httpOptions = {
|
||||||
|
headers: new HttpHeaders({
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: 'Bearer' + this.tokenStorage.getToken(),
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
getStockData(): Observable<any> {
|
||||||
|
return this.http.get(API_URL + 'portfolio', {
|
||||||
|
headers: this.httpOptions.headers,
|
||||||
|
responseType: 'text',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
showStorage() {
|
showStorage() {
|
||||||
|
@ -31,16 +31,14 @@ export class LoginComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
onSubmit(): void {
|
onSubmit(): void {
|
||||||
const { username, password } = this.form;
|
const { username, password } = this.form;
|
||||||
console.log(username, password);
|
|
||||||
this.authService.login(username, password).subscribe(
|
this.authService.login(username, password).subscribe(
|
||||||
(data) => {
|
(data) => {
|
||||||
this.tokenStorage.saveToken(data.accessToken);
|
this.tokenStorage.saveToken(data.data.token);
|
||||||
this.tokenStorage.saveUser(data);
|
this.tokenStorage.saveUser(data.data);
|
||||||
|
|
||||||
this.isLoginFailed = false;
|
this.isLoginFailed = false;
|
||||||
this.isLoggedIn = true;
|
this.isLoggedIn = true;
|
||||||
this.accountName = username;
|
this.accountName = username;
|
||||||
console.log(this.isLoggedIn);
|
|
||||||
this.router.navigate(['']);
|
this.router.navigate(['']);
|
||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user