Added logout function.
This commit is contained in:
		
							parent
							
								
									4d5d32a064
								
							
						
					
					
						commit
						b735929a02
					
				
					 1 changed files with 20 additions and 0 deletions
				
			
		
							
								
								
									
										20
									
								
								logout.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								logout.js
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,20 @@ | ||||||
|  | //VARIBLES
 | ||||||
|  | 
 | ||||||
|  | let username = localStorage.getItem('username'); | ||||||
|  | 
 | ||||||
|  | //LOGOUT FETCH FUNCTION
 | ||||||
|  | 
 | ||||||
|  | async function logout() { | ||||||
|  |     let sendLogoutInfo = { "name": username } | ||||||
|  |     fetch('/api/logout/', { | ||||||
|  |       method: 'POST', | ||||||
|  |       headers: { | ||||||
|  |         'Content-Type': 'application/json', | ||||||
|  |     }, | ||||||
|  |       body: JSON.stringify(sendRegisterInfo), | ||||||
|  |     }); | ||||||
|  |     document.querySelector("#errormessage").innerHTML = 'Logged out.' | ||||||
|  |     localStorage.removeItem('username') | ||||||
|  | 
 | ||||||
|  |   } | ||||||
|  |    | ||||||
		Loading…
	
		Reference in a new issue