use the new backend services

This commit is contained in:
Sven Czarnian
2022-11-04 15:28:47 +01:00
parent 7807c2784c
commit 6882c41089
2 changed files with 6 additions and 16 deletions

View File

@@ -1,7 +1,6 @@
import axios from 'axios';
import { createContext, Dispatch, SetStateAction, useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Configuration } from '../services';
import { Auth } from '../services';
import { User } from '../types';
const AuthContext = createContext<{
@@ -30,12 +29,8 @@ export const AuthProvider = ({ children }: { children: any }) => {
const navigate = useNavigate();
useEffect(() => {
axios.get<User>(`${Configuration.resourceServer}/auth/user`, {
headers: {
Authorization: `Bearer ${sessionStorage.getItem('token')}`,
},
}).then((response) => {
setAuth({ valid: true, user: response.data });
Auth.user().then((user) => {
setAuth({ valid: true, user });
}).catch(() => {
setAuth({
valid: false,

View File

@@ -1,7 +1,6 @@
import axios from 'axios';
import React, { Dispatch, SetStateAction, useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Configuration } from '../services';
import { System } from '../services';
const TimeContext = React.createContext<{
offset: number;
@@ -14,14 +13,10 @@ export const TimeProvider = ({ children }: { children: any }) => {
useEffect(() => {
const estimateTimeOffset = async () => {
axios.get<number>(`${Configuration.resourceServer}/system/timestamp`, {
headers: {
Authorization: `Bearer ${sessionStorage.getItem('token')}`,
},
}).then((response) => {
System.timestamp().then((timestamp) => {
// calculate the time offset (not accurate) between the server and the client to show "correct" times
const clientTimeUtc = new Date().getTime()
const serverTimeUtc = response.data;
const serverTimeUtc = timestamp;
setOffset(serverTimeUtc - clientTimeUtc);
}).catch(() => {
setOffset(0);