chore: update dependencies and refactor auth store for improved token handling

This commit is contained in:
2026-03-05 21:59:50 +08:00
parent 1a6c8524d3
commit 66245c149b
4 changed files with 54 additions and 57 deletions

View File

@@ -5,8 +5,6 @@ import { LogIn, LockKeyhole } from "lucide-react"
export { BaseHeader } from './modules/BaseHeader'
import { useMemo } from 'react';
import { useLocation, useNavigate } from '@tanstack/react-router';
import { useMe } from "./hooks"
type Props = {
children?: React.ReactNode,
@@ -27,8 +25,6 @@ export const AuthProvider = ({ children, mustLogin }: Props) => {
return store.openLinkList.some(item => location.pathname.startsWith(item))
}, [location.pathname])
const loginUrl = '/root/login/?redirect=' + encodeURIComponent(window.location.href);
const me = useMe()
console.log('me', me, me.error);
if (mustLogin && !store.me && !isOpen) {
return (
<div className="w-full h-full min-h-screen flex items-center justify-center bg-background">

View File

@@ -89,16 +89,17 @@ export const useLayoutStore = create<LayoutStore>((set, get) => ({
isAdmin: false,
setIsAdmin: (isAdmin) => set({ isAdmin }),
init: async () => {
const token = await queryLogin.getToken();
await queryLogin.init();
const token = await queryLogin.checkLocalToken();
if (token) {
set({ me: {} });
try {
const data = await stackQueryClient.fetchQuery({
queryKey: authQueryKeys.me,
}) as UserInfo;
console.log('Fetched user info:', data);
if (data) {
set({ me: data, isAdmin: data.orgs?.includes?.('admin') || false });
// const data = await stackQueryClient.fetchQuery({
// queryKey: authQueryKeys.me,
// }) as UserInfo;
const userInfo = await queryLogin.checkLocalUser();
if (userInfo) {
set({ me: userInfo as UserInfo, isAdmin: userInfo.orgs?.includes?.('admin') || false });
} else {
set({ me: undefined, isAdmin: false });
}