use the new backend services
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user