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 { Button } from 'primereact/button';
|
||||||
import { Card } from 'primereact/card';
|
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 = () => {
|
export const Login: React.FC = () => {
|
||||||
// reset every old token
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
useEffect(() => Session.reset(), []);
|
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 redirectToVatsim = () => {
|
||||||
const url = [
|
const url = [
|
||||||
|
|||||||
Reference in New Issue
Block a user