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
 | ||||
| myStorage = window.localStorage; | ||||
| // //IF NOT LOGGED IN DON'T SHOW LOGOUT BUTTON
 | ||||
| while (username === null) { | ||||
|   document.getElementById("logoutbutton").style.display = "none"; | ||||
| } | ||||
| // //VARIBLES
 | ||||
| // myStorage = window.localStorage;
 | ||||
| // allCookies = document.cookie;
 | ||||
| 
 | ||||
| //LOGOUT FETCH FUNCTION
 | ||||
| 
 | ||||
|  | @ -17,33 +14,19 @@ async function logout() { | |||
|     body: JSON.stringify(sendLogoutInfo), | ||||
|   }); | ||||
|   document.querySelector("#errormessage").innerHTML = 'Logged out.' | ||||
|   document.getElementById("logoutbutton").style.display = "none"; | ||||
|   localStorage.removeItem('username') | ||||
|   username = null; | ||||
|   loggedIn() | ||||
| } | ||||
| 
 | ||||
| //CHECKS TO SEE IF USERNAME MATCHES TOKEN 
 | ||||
| let tokenUpdate = window.setInterval(checkToken, 1000); | ||||
| // // IF THERE IS A TOKEN BUT NO USERNAME LOGOUT
 | ||||
| // if (allCookies !== '' && myStorage.length === 0) {
 | ||||
| //   logout()
 | ||||
| // }
 | ||||
| 
 | ||||
| async function checkToken() { | ||||
|   const response = await fetch(`api/token/${username}/`); | ||||
|   const matches = await response.json(); | ||||
| 
 | ||||
|   //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' | ||||
| } | ||||
| // // IF THERE IS NO COOKIE BUT A USERNAME GET RID OF USERNAME LOCALLY.
 | ||||
| // if (allCookies === '' && myStorage.length !== 0) {
 | ||||
| //   localStorage.removeItem('username')
 | ||||
| //   document.querySelector("#loggeduser").innerHTML = 'You are not logged in'
 | ||||
| // }
 | ||||
		Loading…
	
		Reference in a new issue