|
|
|
|
@ -3,9 +3,8 @@ import { Alert, Button, Form, Input, Space, Typography } from "antd";
|
|
|
|
|
import { LockOutlined, UserOutlined } from "@ant-design/icons";
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { Navigate } from "react-router-dom";
|
|
|
|
|
import { isAuthorized$, refreshToken } from "../stores/auth";
|
|
|
|
|
import { isAuthorized$, refreshTokenIntervalFunction, setAuthLocalStorage } from "../stores/auth";
|
|
|
|
|
import { signin, signinError$, signinLoading$ } from "../stores/signin";
|
|
|
|
|
import { logOut } from "../SignOut.jsx";
|
|
|
|
|
|
|
|
|
|
function LoginForm() {
|
|
|
|
|
const signinError = useStore(signinError$);
|
|
|
|
|
@ -13,27 +12,16 @@ function LoginForm() {
|
|
|
|
|
|
|
|
|
|
const onFinish = async (values) => {
|
|
|
|
|
const data = await signin(values);
|
|
|
|
|
localStorage.setItem("access_token", data.access_token);
|
|
|
|
|
localStorage.setItem("refresh_token", data.refresh_token);
|
|
|
|
|
localStorage.setItem("expires_in", data.expires_in);
|
|
|
|
|
setAuthLocalStorage(data);
|
|
|
|
|
|
|
|
|
|
let interval;
|
|
|
|
|
const onTick = async () => {
|
|
|
|
|
try {
|
|
|
|
|
await refreshToken();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
clearInterval(interval);
|
|
|
|
|
logOut();
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setTimeout(async () => {
|
|
|
|
|
await onTick();
|
|
|
|
|
await refreshTokenIntervalFunction();
|
|
|
|
|
interval = setInterval(async () => {
|
|
|
|
|
await onTick();
|
|
|
|
|
await refreshTokenIntervalFunction();
|
|
|
|
|
}, (data.expires_in - 5) * 1000)
|
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|