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