feat(auth): 集成认证授权功能并优化API客户端
- 实现了完整的登录注册认证流程,包括密码验证和用户资料获取 - 集成了JWT令牌管理和自动刷新机制,支持设备ID生成和管理 - 添加了WebSocket连接配置和API基础URL环境变量设置 - 实现了API客户端的请求拦截器,包括令牌验证和错误处理逻辑 - 集成了MD5加密和认证令牌缓存机制,提升安全性 - 添加了多语言国际化支持,包括英语、中文、马来语和印尼语 - 实现了认证状态管理和本地存储持久化功能 - 添加了表单验证schema和错误处理机制,增强用户体验
This commit is contained in:
24
src/main.tsx
24
src/main.tsx
@@ -3,9 +3,19 @@ import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
|
||||
import { RouterProvider } from '@tanstack/react-router'
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import { AppToaster } from '@/components/ui/toaster'
|
||||
import { APP_ROOT_ELEMENT_ID } from '@/constants'
|
||||
import {
|
||||
getCurrentUserProfile,
|
||||
refreshAuthSession,
|
||||
} from '@/features/auth/api/auth-api'
|
||||
import '@/i18n'
|
||||
import { initializeAuthSession } from '@/lib/auth/auth-session'
|
||||
import { prefetchAuthToken } from '@/lib/api/api-client'
|
||||
import {
|
||||
initializeAuthSession,
|
||||
registerCurrentUserInitializer,
|
||||
registerRefreshSessionHandler,
|
||||
} from '@/lib/auth/auth-session'
|
||||
import { queryClient } from '@/lib/query/query-client'
|
||||
import { router } from '@/router'
|
||||
import './style/index.css'
|
||||
@@ -19,12 +29,22 @@ if (!rootElement) {
|
||||
throw new Error('Root element not found')
|
||||
}
|
||||
|
||||
void initializeAuthSession()
|
||||
registerCurrentUserInitializer(getCurrentUserProfile)
|
||||
registerRefreshSessionHandler(refreshAuthSession)
|
||||
|
||||
void initializeAuthSession().then(async () => {
|
||||
try {
|
||||
await prefetchAuthToken()
|
||||
} catch (error) {
|
||||
console.error('Failed to prefetch auth token', error)
|
||||
}
|
||||
})
|
||||
|
||||
createRoot(rootElement).render(
|
||||
<StrictMode>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<RouterProvider router={router} />
|
||||
<AppToaster />
|
||||
{shouldShowQueryDevtools && <ReactQueryDevtools initialIsOpen={false} />}
|
||||
</QueryClientProvider>
|
||||
</StrictMode>,
|
||||
|
||||
Reference in New Issue
Block a user