mirror of
https://github.com/songquanpeng/one-api.git
synced 2026-02-04 13:15:56 +08:00
feat: add new theme berry (#860)
* feat: add theme berry * docs: add development notes * fix: fix blank page * chore: update implementation * fix: fix package.json * chore: update ui copy --------- Co-authored-by: JustSong <songquanpeng@foxmail.com>
This commit is contained in:
20
web/berry/src/utils/route-guard/AuthGuard.js
Normal file
20
web/berry/src/utils/route-guard/AuthGuard.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { useSelector } from 'react-redux';
|
||||
import { useEffect, useContext } from 'react';
|
||||
import { UserContext } from 'contexts/UserContext';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
const AuthGuard = ({ children }) => {
|
||||
const account = useSelector((state) => state.account);
|
||||
const { isUserLoaded } = useContext(UserContext);
|
||||
const navigate = useNavigate();
|
||||
useEffect(() => {
|
||||
if (isUserLoaded && !account.user) {
|
||||
navigate('/login');
|
||||
return;
|
||||
}
|
||||
}, [account, navigate, isUserLoaded]);
|
||||
|
||||
return children;
|
||||
};
|
||||
|
||||
export default AuthGuard;
|
||||
Reference in New Issue
Block a user