WIP Auth redesign.

This commit is contained in:
2019-03-07 23:39:24 -06:00
parent 6bc094f515
commit b23d3d36af
18 changed files with 188 additions and 51 deletions

View File

@ -2,10 +2,10 @@ import { default as Axios, AxiosInstance } from 'axios';
import { ApiToken, LoginSubmit, Measure, Measurement, User } from '@/models';
import { Logger, logService } from '@/services/logging';
import merge from 'lodash.merge';
import authStore from '@/store-modules/auth';
export class PmApiClient {
private http: AxiosInstance;
private authToken?: string;
private log: Logger;
constructor(apiBase: string) {
@ -24,8 +24,6 @@ export class PmApiClient {
this.log.trace('Initialized PmApiClient');
}
public setAuthToken(t: string) { this.authToken = t; }
public async version(): Promise<string> {
const resp = await this.http.get('/version');
return resp.data;
@ -38,12 +36,12 @@ export class PmApiClient {
return resp.data;
}
public async getUser(authToken: string): Promise<User> {
public async getUser(): Promise<User> {
const resp = await this.http.get('/user',
{ headers: { Authorization: 'Bearer ' + authToken }});
{ headers: this.authHeader() });
return merge(resp.data, { authToken }) ;
return merge(resp.data) ;
}
public async getAllUsers(): Promise<User[]> {
@ -206,8 +204,8 @@ export class PmApiClient {
}
private authHeader(): { [key: string]: string } {
if (this.authToken) {
return { Authorization: 'Bearer ' + this.authToken };
if (authStore.authToken) {
return { Authorization: 'Bearer ' + authStore.authToken };
} else {
throw new Error('no authenticated user');
}