mirror of
				https://gitlab.com/Alamantus/Readlebee.git
				synced 2025-11-04 02:07:11 +01:00 
			
		
		
		
	Validate token on initial load
This commit is contained in:
		
							parent
							
								
									cd0baa7605
								
							
						
					
					
						commit
						4498ed002a
					
				
					 2 changed files with 18 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -17,6 +17,8 @@ export const appListeners = (app, state, emitter) => {
 | 
			
		|||
      emitter.emit('render', () => { });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    emitter.emit('render'); // This should hopefully only run once after the DOM is loaded. It prevents routing issues where 'render' hasn't been defined yet
 | 
			
		||||
    app.checkIfLoggedIn(state).then(isLoggedIn => {
 | 
			
		||||
      emitter.emit('render'); // This should hopefully only run once after the DOM is loaded. It prevents routing issues where 'render' hasn't been defined yet
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -19,4 +19,19 @@ export const appUtilities = (app) => {
 | 
			
		|||
    savedSettings[settingsKey] = value;
 | 
			
		||||
    return window.localStorage.setItem('settings', JSON.stringify(savedSettings));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  app.checkIfLoggedIn = (appState) => {
 | 
			
		||||
    return fetch('/api/account/validate', { method: 'post' })
 | 
			
		||||
      .then(response => response.json())
 | 
			
		||||
      .then(response => {
 | 
			
		||||
        if (response.error !== false) {
 | 
			
		||||
          console.warn(response);
 | 
			
		||||
          return false;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        console.info(response.message);
 | 
			
		||||
        appState.isLoggedIn = true;
 | 
			
		||||
        return true;
 | 
			
		||||
      });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue