Fix login loop on self-hosted desktop (#5022)

# Description of Changes
Fix #5017 

Changes the handling of jwt tokens to be stored in local storage as well
as OS keyring so the rest of the app knows that you're logged in.
This commit is contained in:
James Brunton
2025-11-26 13:51:12 +00:00
committed by GitHub
parent 9fdb5295cb
commit 7629d89356
5 changed files with 150 additions and 39 deletions
@@ -126,6 +126,14 @@ export function AuthProvider({ children }: { children: ReactNode }) {
initializeAuth();
// Listen for jwt-available event (triggered by desktop auth or other sources)
const handleJwtAvailable = () => {
console.debug('[Auth] JWT available event received, refreshing session');
void initializeAuth();
};
window.addEventListener('jwt-available', handleJwtAvailable);
// Subscribe to auth state changes
const { data: { subscription } } = springAuth.onAuthStateChange(
async (event: AuthChangeEvent, newSession: Session | null) => {
@@ -162,6 +170,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
return () => {
mounted = false;
window.removeEventListener('jwt-available', handleJwtAvailable);
subscription.unsubscribe();
};
}, []);
@@ -161,8 +161,8 @@ class SpringAuthClient {
return { data: { session: null }, error: null };
}
// Clear potentially invalid token on other errors too
localStorage.removeItem('stirling_jwt');
// Don't clear token for other errors (e.g., backend not ready, network issues)
// The token is still valid, just can't verify it right now
return {
data: { session: null },
error: { message: getErrorMessage(error, 'Unknown error') },