|
|
|
|
@ -1,31 +1,26 @@
|
|
|
|
|
// Copyright (C) 2020-2022 Intel Corporation
|
|
|
|
|
// Copyright (C) 2022 CVAT.ai Corporation
|
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
|
import { Redirect, useParams, useLocation } from 'react-router';
|
|
|
|
|
import { useCookies } from 'react-cookie';
|
|
|
|
|
|
|
|
|
|
export default function LoginWithTokenComponent(): JSX.Element {
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
const { sessionId, token } = useParams<{ sessionId: string; token: string }>();
|
|
|
|
|
const [cookies, setCookie] = useCookies(['sessionid', 'csrftoken']);
|
|
|
|
|
const { token } = useParams<{ token: string }>();
|
|
|
|
|
|
|
|
|
|
const expires1y = new Date(new Date().setFullYear(new Date().getFullYear() + 1));
|
|
|
|
|
const expires2w = new Date(new Date().setDate(new Date().getDate() + 13));
|
|
|
|
|
const search = new URLSearchParams(location.search);
|
|
|
|
|
|
|
|
|
|
setCookie('sessionid', sessionId, { path: '/', expires: expires2w });
|
|
|
|
|
setCookie('csrftoken', token, { path: '/', expires: expires1y });
|
|
|
|
|
|
|
|
|
|
useEffect(
|
|
|
|
|
() => () => {
|
|
|
|
|
window.location.reload();
|
|
|
|
|
() => {
|
|
|
|
|
localStorage.setItem('token', token);
|
|
|
|
|
return () => window.location.reload();
|
|
|
|
|
},
|
|
|
|
|
[cookies.sessionid, cookies.csrftoken],
|
|
|
|
|
[token],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (cookies.sessionid && cookies.csrftoken) {
|
|
|
|
|
if (token) {
|
|
|
|
|
return <Redirect to={search.get('next') || '/tasks'} />;
|
|
|
|
|
}
|
|
|
|
|
return <></>;
|
|
|
|
|
|