check in the initial page if the token is valid

This commit is contained in:
Sven Czarnian
2022-11-04 22:58:37 +01:00
parent 3b81106334
commit 47c09f2fdd

View File

@@ -1,11 +1,27 @@
import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';
import { Button } from 'primereact/button';
import { Card } from 'primereact/card';
import { Configuration, Session } from '../services';
import { useNavigate } from 'react-router-dom';
import { Auth, Configuration, Session } from '../services';
export const Login: React.FC = () => {
// reset every old token
useEffect(() => Session.reset(), []);
const [loading, setLoading] = useState<boolean>(true);
const navigate = useNavigate();
// check if the known bearer token is still valid
useEffect(() => {
Auth.tokenIsValid().then((valid) => {
if (!valid) {
Session.reset();
setLoading(false);
} else {
navigate('/overview');
}
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
if (loading) return <></>;
const redirectToVatsim = () => {
const url = [