1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import Axios from "axios";
6 import { API_HOST } from "../../common/server-api";
8 const API_TOKEN_KEY = 'api_token';
10 export default class AuthService {
12 public saveApiToken(token: string) {
13 localStorage.setItem(API_TOKEN_KEY, token);
16 public removeApiToken() {
17 localStorage.removeItem(API_TOKEN_KEY);
20 public getApiToken() {
21 return localStorage.getItem(API_TOKEN_KEY);
24 public isUserLoggedIn() {
25 return this.getApiToken() !== null;
29 const currentUrl = `${window.location.protocol}//${window.location.host}/token`;
30 window.location.href = `${API_HOST}/login?return_to=${currentUrl}`;
33 public logout(): Promise<any> {
34 const currentUrl = `${window.location.protocol}//${window.location.host}`;
35 return Axios.get(`${API_HOST}/logout?return_to=${currentUrl}`);