-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to login into UI with token from api/v1/auth/login (#2234)
* Allow to login into UI with token from api/v1/auth/login * Update changelog * style * Rev * Rev: Fixed style. Added cva-ui version to UI. Fixed endless redirection with wrong tokens * eslint * revert cvat-core/package-lock.json * Rev: Fixed import order and return type * Revert bindings
- Loading branch information
Showing
5 changed files
with
113 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
cvat-ui/src/components/login-with-token/login-with-token.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (C) 2020 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
import React, { useEffect } from 'react'; | ||
import { Redirect, useParams } from 'react-router'; | ||
import { useCookies } from 'react-cookie'; | ||
|
||
export default function LoginWithTokenComponent(): JSX.Element { | ||
const { sessionId, token } = useParams(); | ||
const [cookies, setCookie] = useCookies(['sessionid', 'csrftoken']); | ||
|
||
const expires1y = new Date(new Date().setFullYear(new Date().getFullYear() + 1)); | ||
const expires2w = new Date(new Date().setDate(new Date().getDate() + 13)); | ||
|
||
setCookie('sessionid', sessionId, { path: '/', expires: expires2w }); | ||
setCookie('csrftoken', token, { path: '/', expires: expires1y }); | ||
|
||
useEffect(() => () => { | ||
window.location.reload(); | ||
}, [cookies.sessionid, cookies.csrftoken]); | ||
|
||
if (cookies.sessionid && cookies.csrftoken) { | ||
return (<Redirect to='/tasks' />); | ||
} | ||
return (<></>); | ||
} |