Fix version display problem when server does not require auth
This commit is contained in:
@@ -43,7 +43,7 @@ const ProtectedRoute = ({ children }: ProtectedRouteProps) => {
|
|||||||
|
|
||||||
if (!status.auth_configured && status.access_token) {
|
if (!status.auth_configured && status.access_token) {
|
||||||
// If auth is not configured, use the guest token
|
// If auth is not configured, use the guest token
|
||||||
useAuthStore.getState().login(status.access_token, true)
|
useAuthStore.getState().login(status.access_token, true, status.core_version, status.api_version)
|
||||||
if (status.message) {
|
if (status.message) {
|
||||||
toast.info(status.message)
|
toast.info(status.message)
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ const AppContent = () => {
|
|||||||
|
|
||||||
if (!status.auth_configured && status.access_token) {
|
if (!status.auth_configured && status.access_token) {
|
||||||
// If auth is not configured, use the guest token
|
// If auth is not configured, use the guest token
|
||||||
useAuthStore.getState().login(status.access_token, true)
|
useAuthStore.getState().login(status.access_token, true, status.core_version, status.api_version)
|
||||||
if (status.message) {
|
if (status.message) {
|
||||||
toast.info(status.message)
|
toast.info(status.message)
|
||||||
}
|
}
|
||||||
|
@@ -88,20 +88,23 @@ const isGuestToken = (token: string): boolean => {
|
|||||||
// Initialize auth state from localStorage
|
// Initialize auth state from localStorage
|
||||||
const initAuthState = (): { isAuthenticated: boolean; isGuestMode: boolean; coreVersion: string | null; apiVersion: string | null } => {
|
const initAuthState = (): { isAuthenticated: boolean; isGuestMode: boolean; coreVersion: string | null; apiVersion: string | null } => {
|
||||||
const token = localStorage.getItem('LIGHTRAG-API-TOKEN');
|
const token = localStorage.getItem('LIGHTRAG-API-TOKEN');
|
||||||
|
const coreVersion = localStorage.getItem('LIGHTRAG-CORE-VERSION');
|
||||||
|
const apiVersion = localStorage.getItem('LIGHTRAG-API-VERSION');
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return {
|
return {
|
||||||
isAuthenticated: false,
|
isAuthenticated: false,
|
||||||
isGuestMode: false,
|
isGuestMode: false,
|
||||||
coreVersion: null,
|
coreVersion: coreVersion,
|
||||||
apiVersion: null
|
apiVersion: apiVersion
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isAuthenticated: true,
|
isAuthenticated: true,
|
||||||
isGuestMode: isGuestToken(token),
|
isGuestMode: isGuestToken(token),
|
||||||
coreVersion: localStorage.getItem('LIGHTRAG-CORE-VERSION'),
|
coreVersion: coreVersion,
|
||||||
apiVersion: localStorage.getItem('LIGHTRAG-API-VERSION')
|
apiVersion: apiVersion
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -118,7 +121,6 @@ export const useAuthStore = create<AuthState>(set => {
|
|||||||
login: (token, isGuest = false, coreVersion = null, apiVersion = null) => {
|
login: (token, isGuest = false, coreVersion = null, apiVersion = null) => {
|
||||||
localStorage.setItem('LIGHTRAG-API-TOKEN', token);
|
localStorage.setItem('LIGHTRAG-API-TOKEN', token);
|
||||||
|
|
||||||
// 存储版本信息到 localStorage
|
|
||||||
if (coreVersion) {
|
if (coreVersion) {
|
||||||
localStorage.setItem('LIGHTRAG-CORE-VERSION', coreVersion);
|
localStorage.setItem('LIGHTRAG-CORE-VERSION', coreVersion);
|
||||||
}
|
}
|
||||||
@@ -129,19 +131,22 @@ export const useAuthStore = create<AuthState>(set => {
|
|||||||
set({
|
set({
|
||||||
isAuthenticated: true,
|
isAuthenticated: true,
|
||||||
isGuestMode: isGuest,
|
isGuestMode: isGuest,
|
||||||
coreVersion,
|
coreVersion: coreVersion,
|
||||||
apiVersion
|
apiVersion: apiVersion
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
logout: () => {
|
logout: () => {
|
||||||
localStorage.removeItem('LIGHTRAG-API-TOKEN');
|
localStorage.removeItem('LIGHTRAG-API-TOKEN');
|
||||||
|
|
||||||
|
const coreVersion = localStorage.getItem('LIGHTRAG-CORE-VERSION');
|
||||||
|
const apiVersion = localStorage.getItem('LIGHTRAG-API-VERSION');
|
||||||
|
|
||||||
set({
|
set({
|
||||||
isAuthenticated: false,
|
isAuthenticated: false,
|
||||||
isGuestMode: false,
|
isGuestMode: false,
|
||||||
coreVersion: null,
|
coreVersion: coreVersion,
|
||||||
apiVersion: null
|
apiVersion: apiVersion
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user