- 新增Pinia状态管理用于用户认证和全局状态 - 实现JWT认证工具类和API服务封装 - 添加路由权限控制和全局错误处理 - 重构项目结构,新增layouts目录和组件 - 完善工具函数库和常量定义 - 新增404页面和API接口模块 - 优化移动端导航和响应式布局 - 更新依赖并添加开发工具支持
40 lines
794 B
JavaScript
40 lines
794 B
JavaScript
// JWT Token Management Utility
|
|
// Handles storage and retrieval of authentication tokens
|
|
|
|
export const TOKEN_KEY = 'auth_token';
|
|
|
|
export const getToken = () => {
|
|
return localStorage.getItem(TOKEN_KEY);
|
|
};
|
|
|
|
export const setToken = (token) => {
|
|
if (token) {
|
|
localStorage.setItem(TOKEN_KEY, token);
|
|
} else {
|
|
localStorage.removeItem(TOKEN_KEY);
|
|
}
|
|
};
|
|
|
|
export const removeToken = () => {
|
|
localStorage.removeItem(TOKEN_KEY);
|
|
};
|
|
|
|
export const hasToken = () => {
|
|
return !!getToken();
|
|
};
|
|
|
|
// Optional: Add token expiration check if needed
|
|
// export const isTokenExpired = () => {
|
|
// const token = getToken();
|
|
// if (!token) return true;
|
|
// // Add expiration logic here
|
|
// return false;
|
|
// };
|
|
|
|
export default {
|
|
TOKEN_KEY,
|
|
getToken,
|
|
setToken,
|
|
removeToken,
|
|
hasToken
|
|
}; |