From e21e064af352066148e4f45c5c4594ae4b05daf3 Mon Sep 17 00:00:00 2001 From: Michal Klobukowski Date: Mon, 16 Jul 2018 10:49:18 +0200 Subject: [PATCH] Add AuthService constructor with serverApi param Feature #13817 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- src/services/auth-service/auth-service.ts | 7 +++++-- src/services/services.ts | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/services/auth-service/auth-service.ts b/src/services/auth-service/auth-service.ts index e953a75d..5b21a616 100644 --- a/src/services/auth-service/auth-service.ts +++ b/src/services/auth-service/auth-service.ts @@ -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 => { - return serverApi + return this.serverApi .get('/users/current') .then(resp => ({ email: resp.data.email, diff --git a/src/services/services.ts b/src/services/services.ts index 143e97bd..88f6ffae 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -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); -- 2.30.2