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 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) {
|
||||
toast.info(status.message)
|
||||
}
|
||||
@@ -126,7 +126,7 @@ const AppContent = () => {
|
||||
|
||||
if (!status.auth_configured && status.access_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) {
|
||||
toast.info(status.message)
|
||||
}
|
||||
|
@@ -88,20 +88,23 @@ const isGuestToken = (token: string): boolean => {
|
||||
// Initialize auth state from localStorage
|
||||
const initAuthState = (): { isAuthenticated: boolean; isGuestMode: boolean; coreVersion: string | null; apiVersion: string | null } => {
|
||||
const token = localStorage.getItem('LIGHTRAG-API-TOKEN');
|
||||
const coreVersion = localStorage.getItem('LIGHTRAG-CORE-VERSION');
|
||||
const apiVersion = localStorage.getItem('LIGHTRAG-API-VERSION');
|
||||
|
||||
if (!token) {
|
||||
return {
|
||||
isAuthenticated: false,
|
||||
isGuestMode: false,
|
||||
coreVersion: null,
|
||||
apiVersion: null
|
||||
coreVersion: coreVersion,
|
||||
apiVersion: apiVersion
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
isAuthenticated: true,
|
||||
isGuestMode: isGuestToken(token),
|
||||
coreVersion: localStorage.getItem('LIGHTRAG-CORE-VERSION'),
|
||||
apiVersion: localStorage.getItem('LIGHTRAG-API-VERSION')
|
||||
coreVersion: coreVersion,
|
||||
apiVersion: apiVersion
|
||||
};
|
||||
};
|
||||
|
||||
@@ -118,7 +121,6 @@ export const useAuthStore = create<AuthState>(set => {
|
||||
login: (token, isGuest = false, coreVersion = null, apiVersion = null) => {
|
||||
localStorage.setItem('LIGHTRAG-API-TOKEN', token);
|
||||
|
||||
// 存储版本信息到 localStorage
|
||||
if (coreVersion) {
|
||||
localStorage.setItem('LIGHTRAG-CORE-VERSION', coreVersion);
|
||||
}
|
||||
@@ -129,19 +131,22 @@ export const useAuthStore = create<AuthState>(set => {
|
||||
set({
|
||||
isAuthenticated: true,
|
||||
isGuestMode: isGuest,
|
||||
coreVersion,
|
||||
apiVersion
|
||||
coreVersion: coreVersion,
|
||||
apiVersion: apiVersion
|
||||
});
|
||||
},
|
||||
|
||||
logout: () => {
|
||||
localStorage.removeItem('LIGHTRAG-API-TOKEN');
|
||||
|
||||
const coreVersion = localStorage.getItem('LIGHTRAG-CORE-VERSION');
|
||||
const apiVersion = localStorage.getItem('LIGHTRAG-API-VERSION');
|
||||
|
||||
set({
|
||||
isAuthenticated: false,
|
||||
isGuestMode: false,
|
||||
coreVersion: null,
|
||||
apiVersion: null
|
||||
coreVersion: coreVersion,
|
||||
apiVersion: apiVersion
|
||||
});
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user