Frontend: checking for username and token mismatch
This commit is contained in:
		
							parent
							
								
									5543b1e8c5
								
							
						
					
					
						commit
						d875ce398f
					
				
					 1 changed files with 23 additions and 12 deletions
				
			
		
							
								
								
									
										35
									
								
								chat.js
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								chat.js
									
									
									
									
									
								
							|  | @ -12,17 +12,21 @@ form.addEventListener("submit", async function (event) { | |||
| 
 | ||||
|     formMessage = formData.get('message').toString(); | ||||
| 
 | ||||
|         //KINDA UNNECESSARY
 | ||||
|         //CHECKS TO SEE IF THE PERSON IS LOGGED IN IN ORDER TO SEND A MESSAGE.
 | ||||
|         const response = await fetch(`api/token/${username}/`); | ||||
|         const matches = await response.json(); | ||||
|        | ||||
|         //YES THIS IS CONFUSING I KNOW.
 | ||||
|         if (matches.status === "ok") { | ||||
|           sendMessage() | ||||
|         } else { | ||||
|             document.querySelector("#errormessage").innerHTML = 'Username and token mismatch. Try logging in again.' | ||||
|         } | ||||
|     //KINDA UNNECESSARY
 | ||||
|     //CHECKS TO SEE IF THE PERSON IS LOGGED IN IN ORDER TO SEND A MESSAGE.
 | ||||
|     const response = await fetch(`api/token/${username}/`); | ||||
|     const matches = await response.json(); | ||||
| 
 | ||||
|     //YES THIS IS CONFUSING I KNOW.
 | ||||
|     if (matches.status === "ok") { | ||||
|         sendMessage() | ||||
|     } else { | ||||
|         const mismatch = 'Username and token mismatch. Try logging in again.' | ||||
|         printText(mismatch.bold()) | ||||
|         logout() | ||||
|         localStorage.removeItem('username') | ||||
|     } | ||||
| 
 | ||||
| }) | ||||
| 
 | ||||
| //SEND MESSAGE FETCH FUNCTION
 | ||||
|  | @ -86,4 +90,11 @@ function loggedIn() { | |||
| loggedIn() | ||||
| 
 | ||||
| 
 | ||||
| //REVIECE USERS PRONOUNS
 | ||||
| //REVIECE USERS PRONOUNS
 | ||||
| 
 | ||||
| async function getPronouns() { | ||||
| const response = await fetch(`api/users/${username}/`); | ||||
| const data = await response.json(); | ||||
| pronouns = data.pronouns | ||||
| return pronouns; | ||||
| } | ||||
		Loading…
	
		Reference in a new issue