Add AuthService constructor with serverApi param
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Mon, 16 Jul 2018 08:49:18 +0000 (10:49 +0200)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Mon, 16 Jul 2018 08:49:18 +0000 (10:49 +0200)
Feature #13817

Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski@contractors.roche.com>

src/services/auth-service/auth-service.ts
src/services/services.ts

index e953a75d14aabbcd52a2d61fcf32e260d83717f3..5b21a61634be451a75841435e156e265ab0136a7 100644 (file)
@@ -2,8 +2,9 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { API_HOST, serverApi } from "../../common/api/server-api";
+import { API_HOST } from "../../common/api/server-api";
 import { User } from "../../models/user";
+import { AxiosInstance } from "../../../node_modules/axios";
 
 export const API_TOKEN_KEY = 'apiToken';
 export const USER_EMAIL_KEY = 'userEmail';
@@ -23,6 +24,8 @@ export interface UserDetailsResponse {
 
 export default class AuthService {
 
+    constructor(protected serverApi: AxiosInstance) { }
+
     public saveApiToken(token: string) {
         localStorage.setItem(API_TOKEN_KEY, token);
     }
@@ -82,7 +85,7 @@ export default class AuthService {
     }
 
     public getUserDetails = (): Promise<User> => {
-        return serverApi
+        return this.serverApi
             .get<UserDetailsResponse>('/users/current')
             .then(resp => ({
                 email: resp.data.email,
index 143e97bdaf2dbbeff82b3e2cb5b23a691a0505e0..88f6ffaefd46527571d4a0181364a6d0663c03fa 100644 (file)
@@ -7,6 +7,6 @@ import GroupsService from "./groups-service/groups-service";
 import { serverApi } from "../common/api/server-api";
 import ProjectService from "./project-service/project-service";
 
-export const authService = new AuthService();
+export const authService = new AuthService(serverApi);
 export const groupsService = new GroupsService(serverApi);
 export const projectService = new ProjectService(serverApi);