feat: guest mode
This commit is contained in:
@@ -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;
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user