refactor: getLocalAuthData

This commit is contained in:
Tristan Yang
2022-12-15 19:39:27 +08:00
parent 160e9678fe
commit 66589bc5bf
4 changed files with 452 additions and 474 deletions
+3 -8
View File
@@ -1,6 +1,6 @@
import { useEffect, useState, useCallback, useRef } from "react";
import toast from "react-hot-toast";
import BASE_URL, { KEY_EXPIRE, KEY_REFRESH_TOKEN, KEY_TOKEN } from "../../../app/config";
import BASE_URL from "../../../app/config";
import { setReady } from "../../../app/slices/ui";
import {
fillChannels,
@@ -23,6 +23,7 @@ import { ServerEvent, UsersStateEvent } from "../../../types/sse";
import { isNull, omitBy } from "lodash";
import { useRenewMutation } from "../../../app/services/auth";
import dayjs from "dayjs";
import { getLocalAuthData } from "../../utils";
const getQueryString = (params: { [key: string]: string }) => {
const sp = new URLSearchParams();
@@ -33,13 +34,7 @@ const getQueryString = (params: { [key: string]: string }) => {
});
return sp.toString();
};
const getLocalAuthData = () => {
return {
token: localStorage.getItem(KEY_TOKEN) || "",
refreshToken: localStorage.getItem(KEY_REFRESH_TOKEN) || "",
expireTime: Number(localStorage.getItem(KEY_EXPIRE) || +new Date())
};
};
let SSE: EventSource | undefined = undefined;
let connectionIsOpen = false;
let aliveInter: number = 0;