feat: guest mode

This commit is contained in:
Tristan Yang
2022-08-30 23:20:00 +08:00
parent ac3289b255
commit 5ffd9748fd
11 changed files with 179 additions and 44 deletions
+37
View File
@@ -0,0 +1,37 @@
import { FC, ReactElement, useEffect } from "react";
import { Navigate } from "react-router-dom";
import { useGetInitializedQuery, useLazyGuestLoginQuery } from "../../app/services/auth";
import { useGetLoginConfigQuery } from "../../app/services/server";
import { useAppSelector } from "../../app/store";
interface Props {
children: ReactElement;
}
const GuestOnly: FC<Props> = ({ children }) => {
const { data: loginConfig, isLoading: fetchingConfig } = useGetLoginConfigQuery();
const { isLoading: initChecking } = useGetInitializedQuery();
const [guestLogin, { isLoading: guestSigning }] = useLazyGuestLoginQuery();
const { token, user, initialized } = useAppSelector((store) => store.authData);
useEffect(() => {
// 未登录
if (!token) {
guestLogin();
}
}, [token, user]);
// 已登录的非guest用户
if (token && user?.create_by !== "guest") {
return <Navigate to={`/`} replace />;
}
if (initChecking || guestSigning || fetchingConfig) return null;
// console.log("wtfff", token, user);
// 检查有没有开启guest mode
if (!loginConfig?.guest) return <Navigate to={`/v/off`} replace />;
// 未初始化 则先走setup 流程
if (!initialized) return <Navigate to={`/onboarding`} replace />;
return token ? children : null;
};
export default GuestOnly;
+1 -1
View File
@@ -155,7 +155,7 @@ const Message: FC<IProps> = ({
edited
})
)}
{reactions && <Reaction mid={mid} reactions={reactions} />}
{reactions && <Reaction mid={mid} reactions={reactions} readOnly={readOnly} />}
</div>
</div>
</ContextMenu>