refactor: guest mode

This commit is contained in:
Tristan Yang
2022-09-02 12:39:40 +08:00
parent 333cbb8b4b
commit c4435662c0
8 changed files with 50 additions and 26 deletions
-4
View File
@@ -43,10 +43,6 @@ const tables = [
storeName: "ui",
description: "store UI state"
}
// {
// storeName: "message",
// description: "store message with key-val full data",
// },
];
const initCache = () => {
const uid = localStorage.getItem(KEY_UID) || "";
+1
View File
@@ -4,6 +4,7 @@ const BASE_URL = process.env.REACT_APP_RELEASE
? `${location.origin}/api`
: `https://dev.voce.chat/api`;
export const CACHE_VERSION = `0.3.1`;
export const GuestRoutes = ["/", "/chat", "/chat/channel/:channel_id"];
export const ContentTypes = {
text: "text/plain",
markdown: "text/markdown",
+3 -3
View File
@@ -21,7 +21,7 @@ interface State {
const loginUser = localStorage.getItem(KEY_LOGIN_USER) || "";
const initialState: State = {
initialized: true,
guest: false,
guest: loginUser ? JSON.parse(loginUser).create_by == "guest" : false,
user: loginUser ? JSON.parse(loginUser) : undefined,
token: localStorage.getItem(KEY_TOKEN) || "",
expireTime: Number(localStorage.getItem(KEY_EXPIRE) || +new Date()),
@@ -43,10 +43,10 @@ const authDataSlice = createSlice({
reducers: {
setAuthData(state, { payload }: PayloadAction<AuthData>) {
const { initialized = true, user, token, refresh_token, expired_in = 0 } = payload;
const { uid } = user;
const { uid, create_by } = user;
state.initialized = initialized;
state.user = user;
// state.guest = user.create_by == "guest";
state.guest = create_by == "guest";
state.token = token;
state.refreshToken = refresh_token;
// 当前时间往后推expire时长