resolve the TODOs

This commit is contained in:
Sven Czarnian
2022-11-05 02:28:16 +01:00
parent 03919f7b97
commit 8c6d6ae5e2
2 changed files with 12 additions and 7 deletions

View File

@@ -4,7 +4,7 @@ import { Card } from 'primereact/card';
import { DataTable } from 'primereact/datatable'; import { DataTable } from 'primereact/datatable';
import { Password } from 'primereact/password'; import { Password } from 'primereact/password';
import { AuthContext } from '../contexts'; import { AuthContext } from '../contexts';
import { Auth } from '../services'; import { Auth, Session } from '../services';
import { BackendReturnStatus } from '../types'; import { BackendReturnStatus } from '../types';
import { Column } from 'primereact/column'; import { Column } from 'primereact/column';
@@ -18,9 +18,8 @@ export const Overview: React.FC = () => {
const regenerateKey = async () => { const regenerateKey = async () => {
Auth.refreshRadarScopeKey().then((status) => { Auth.refreshRadarScopeKey().then((status) => {
if (status === BackendReturnStatus.Unauthorized) { if (status === BackendReturnStatus.Unauthorized) {
Session.setLastShownComponent('/overview');
Auth.triggerLoginFlow(); Auth.triggerLoginFlow();
// TODO reload user data in auth
// TODO store current URL and get back after login
} else if (status === BackendReturnStatus.Failure) { } else if (status === BackendReturnStatus.Failure) {
setStatusMessage({ setStatusMessage({
error: true, error: true,

View File

@@ -1,5 +1,6 @@
import React, { Dispatch, SetStateAction, useEffect, useState } from 'react'; import React, { Dispatch, SetStateAction, useEffect, useRef, useState } from 'react';
import { Auth, System } from '../services'; import { useLocation } from 'react-router-dom';
import { Auth, Session, System } from '../services';
import { BackendReturnStatus } from '../types'; import { BackendReturnStatus } from '../types';
const TimeContext = React.createContext<{ const TimeContext = React.createContext<{
@@ -9,14 +10,19 @@ const TimeContext = React.createContext<{
export const TimeProvider = ({ children }: { children: any }) => { export const TimeProvider = ({ children }: { children: any }) => {
const [offset, setOffset] = useState<number>(0); const [offset, setOffset] = useState<number>(0);
const location = useLocation();
const refLocation = useRef<string>();
refLocation.current = location.pathname;
useEffect(() => { useEffect(() => {
const estimateTimeOffset = async () => { const estimateTimeOffset = async () => {
System.timestamp().then((response) => { System.timestamp().then((response) => {
if (response.status === BackendReturnStatus.Unauthorized) { if (response.status === BackendReturnStatus.Unauthorized) {
if (refLocation.current) {
Session.setLastShownComponent(refLocation.current);
}
Auth.triggerLoginFlow(); Auth.triggerLoginFlow();
// TODO reload user data in auth
// TODO store current URL and get back after login
} else if (response.status === BackendReturnStatus.Ok) { } else if (response.status === BackendReturnStatus.Ok) {
// 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()