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 { createContext, Dispatch, SetStateAction, useEffect, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { Configuration } from '../services';
|
import { Auth } from '../services';
|
||||||
import { User } from '../types';
|
import { User } from '../types';
|
||||||
|
|
||||||
const AuthContext = createContext<{
|
const AuthContext = createContext<{
|
||||||
@@ -30,12 +29,8 @@ export const AuthProvider = ({ children }: { children: any }) => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
axios.get<User>(`${Configuration.resourceServer}/auth/user`, {
|
Auth.user().then((user) => {
|
||||||
headers: {
|
setAuth({ valid: true, user });
|
||||||
Authorization: `Bearer ${sessionStorage.getItem('token')}`,
|
|
||||||
},
|
|
||||||
}).then((response) => {
|
|
||||||
setAuth({ valid: true, user: response.data });
|
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
setAuth({
|
setAuth({
|
||||||
valid: false,
|
valid: false,
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import axios from 'axios';
|
|
||||||
import React, { Dispatch, SetStateAction, useEffect, useState } from 'react';
|
import React, { Dispatch, SetStateAction, useEffect, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { Configuration } from '../services';
|
import { System } from '../services';
|
||||||
|
|
||||||
const TimeContext = React.createContext<{
|
const TimeContext = React.createContext<{
|
||||||
offset: number;
|
offset: number;
|
||||||
@@ -14,14 +13,10 @@ export const TimeProvider = ({ children }: { children: any }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const estimateTimeOffset = async () => {
|
const estimateTimeOffset = async () => {
|
||||||
axios.get<number>(`${Configuration.resourceServer}/system/timestamp`, {
|
System.timestamp().then((timestamp) => {
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${sessionStorage.getItem('token')}`,
|
|
||||||
},
|
|
||||||
}).then((response) => {
|
|
||||||
// calculate the time offset (not accurate) between the server and the client to show "correct" times
|
// calculate the time offset (not accurate) between the server and the client to show "correct" times
|
||||||
const clientTimeUtc = new Date().getTime()
|
const clientTimeUtc = new Date().getTime()
|
||||||
const serverTimeUtc = response.data;
|
const serverTimeUtc = timestamp;
|
||||||
setOffset(serverTimeUtc - clientTimeUtc);
|
setOffset(serverTimeUtc - clientTimeUtc);
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
setOffset(0);
|
setOffset(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user