feat: 更新了部分依赖包的开发状态标记

This commit is contained in:
zyh
2024-10-22 02:46:31 +00:00
parent 663bc4c3b0
commit cd5b6243a5
14 changed files with 366 additions and 46 deletions

25
app/hooks/useAuth.ts Normal file
View File

@@ -0,0 +1,25 @@
import { useState, useEffect } from 'react';
import { useNavigate } from '@remix-run/react';
export function useAuth() {
const [isAuthenticated, setIsAuthenticated] = useState(false);
const navigate = useNavigate();
useEffect(() => {
const token = localStorage.getItem('token');
setIsAuthenticated(!!token);
}, []);
const login = (token: string) => {
localStorage.setItem('token', token);
setIsAuthenticated(true);
};
const logout = () => {
localStorage.removeItem('token');
setIsAuthenticated(false);
navigate('/login');
};
return { isAuthenticated, login, logout };
}