check in the initial page if the token is valid
This commit is contained in:
@@ -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 = [
|
||||
|
||||
Reference in New Issue
Block a user