Misc Changes
This commit is contained in:
		
							parent
							
								
									ed3aeffc5c
								
							
						
					
					
						commit
						7f97031409
					
				
					 1 changed files with 13 additions and 30 deletions
				
			
		
							
								
								
									
										43
									
								
								logout.js
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								logout.js
									
									
									
									
									
								
							|  | @ -1,9 +1,6 @@ | ||||||
| //VARIBLES
 | // //VARIBLES
 | ||||||
| myStorage = window.localStorage; | // myStorage = window.localStorage;
 | ||||||
| // //IF NOT LOGGED IN DON'T SHOW LOGOUT BUTTON
 | // allCookies = document.cookie;
 | ||||||
| while (username === null) { |  | ||||||
|   document.getElementById("logoutbutton").style.display = "none"; |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| //LOGOUT FETCH FUNCTION
 | //LOGOUT FETCH FUNCTION
 | ||||||
| 
 | 
 | ||||||
|  | @ -17,33 +14,19 @@ async function logout() { | ||||||
|     body: JSON.stringify(sendLogoutInfo), |     body: JSON.stringify(sendLogoutInfo), | ||||||
|   }); |   }); | ||||||
|   document.querySelector("#errormessage").innerHTML = 'Logged out.' |   document.querySelector("#errormessage").innerHTML = 'Logged out.' | ||||||
|  |   document.getElementById("logoutbutton").style.display = "none"; | ||||||
|   localStorage.removeItem('username') |   localStorage.removeItem('username') | ||||||
|   username = null; |   username = null; | ||||||
|   loggedIn() |   loggedIn() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //CHECKS TO SEE IF USERNAME MATCHES TOKEN 
 | // // IF THERE IS A TOKEN BUT NO USERNAME LOGOUT
 | ||||||
| let tokenUpdate = window.setInterval(checkToken, 1000); | // if (allCookies !== '' && myStorage.length === 0) {
 | ||||||
|  | //   logout()
 | ||||||
|  | // }
 | ||||||
| 
 | 
 | ||||||
| async function checkToken() { | // // IF THERE IS NO COOKIE BUT A USERNAME GET RID OF USERNAME LOCALLY.
 | ||||||
|   const response = await fetch(`api/token/${username}/`); | // if (allCookies === '' && myStorage.length !== 0) {
 | ||||||
|   const matches = await response.json(); | //   localStorage.removeItem('username')
 | ||||||
| 
 | //   document.querySelector("#loggeduser").innerHTML = 'You are not logged in'
 | ||||||
|   //YES THIS IS CONFUSING I KNOW.
 | // }
 | ||||||
|   if (matches.status === "fail") { |  | ||||||
|     loggedOut() |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   // IF NO USERNAME BUT HAS A TOKEN THEN LOGOUT
 |  | ||||||
| 
 |  | ||||||
|   if (matches.status === "ok" && myStorage.length === 0) { |  | ||||||
|     logout() |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| //AND IF THEY DON'T HAVE A TOKEN CLEARS THE LOCAL STORED USERNAME
 |  | ||||||
| 
 |  | ||||||
| function loggedOut() { |  | ||||||
|   localStorage.removeItem('username') |  | ||||||
|   document.querySelector("#loggeduser").innerHTML = 'You are not logged in' |  | ||||||
| } |  | ||||||
		Loading…
	
		Reference in a new issue