Implement login frontend
This commit is contained in:
		
							parent
							
								
									5141ebf0f1
								
							
						
					
					
						commit
						7c3bd135d1
					
				| @ -5,9 +5,10 @@ function request(method, path, data = null) { | |||||||
| 			if (xhr.status >= 200 && xhr.status < 300) | 			if (xhr.status >= 200 && xhr.status < 300) | ||||||
| 				resolve(xhr.responseText ? JSON.parse(xhr.responseText) : null); | 				resolve(xhr.responseText ? JSON.parse(xhr.responseText) : null); | ||||||
| 			else | 			else | ||||||
| 				reject(xhr.responseText ? JSON.parse(xhr.responseText).title : "HTTP " + xhr.status); | 				reject(xhr.responseText || "HTTP " + xhr.status); | ||||||
| 		} | 		} | ||||||
| 		xhr.onerror = () => reject("Something went wrong"); | 		xhr.onerror = () => reject("Something went wrong"); | ||||||
|  | 		xhr.withCredentials = true; | ||||||
| 		xhr.open(method, import.meta.env.VITE_API_URL + path); | 		xhr.open(method, import.meta.env.VITE_API_URL + path); | ||||||
| 		if (data) xhr.setRequestHeader("Content-Type", "application/json"), | 		if (data) xhr.setRequestHeader("Content-Type", "application/json"), | ||||||
| 		xhr.send(JSON.stringify(data)); | 		xhr.send(JSON.stringify(data)); | ||||||
|  | |||||||
| @ -1,17 +1,43 @@ | |||||||
| <script setup> | <script setup> | ||||||
|  | import { request } from "../assets/helpers.js"; | ||||||
|  | import { ref } from "vue"; | ||||||
| 
 | 
 | ||||||
|  | const username = ref(null); | ||||||
|  | const password = ref(null); | ||||||
|  | 
 | ||||||
|  | const error = ref(""); | ||||||
|  | 
 | ||||||
|  | function login() { | ||||||
|  | 	request("POST", "/login", { username: username.value.value, password: password.value.value }) | ||||||
|  | 		.then(success) | ||||||
|  | 		.catch(err => error.value = err); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function success() { | ||||||
|  | 	alert("Successfully logged in"); | ||||||
|  | } | ||||||
| </script> | </script> | ||||||
| 
 | 
 | ||||||
| <template> | <template> | ||||||
|   <main> |   <main> | ||||||
|     <h1>LOGIN</h1> |     <h1>LOGIN</h1> | ||||||
|  | 
 | ||||||
|     <br> |     <br> | ||||||
|     <span>Brugernavn</span><br> | 
 | ||||||
|     <input id="usernameInput" type="text"> | 	<label> | ||||||
|  | 		Username <br> | ||||||
|  | 		<input ref="username" type="text" required> | ||||||
|  | 	</label> | ||||||
|  | 
 | ||||||
| 	<br><br> | 	<br><br> | ||||||
|     <span>Password</span><br> | 
 | ||||||
|     <input id="passwordInput" type="password"> | 	<label> | ||||||
|     <br><br><br> | 		Password <br> | ||||||
|     <button>Login</button> | 		<input ref="password" type="password" required> | ||||||
|  | 	</label> | ||||||
|  | 
 | ||||||
|  | 	<p class="error">{{ error }}</p> | ||||||
|  | 
 | ||||||
|  |     <button @click="login">Login</button> | ||||||
|   </main> |   </main> | ||||||
| </template> | </template> | ||||||
|  | |||||||
| @ -26,14 +26,14 @@ function success() { | |||||||
| 
 | 
 | ||||||
| 	<label> | 	<label> | ||||||
| 		Username <br> | 		Username <br> | ||||||
| 		<input ref="username" type="text"> | 		<input ref="username" type="text" required> | ||||||
| 	</label> | 	</label> | ||||||
| 
 | 
 | ||||||
| 	<br><br> | 	<br><br> | ||||||
| 
 | 
 | ||||||
| 	<label> | 	<label> | ||||||
| 		Password <br> | 		Password <br> | ||||||
| 		<input ref="password" type="password"> | 		<input ref="password" type="password" required> | ||||||
| 	</label> | 	</label> | ||||||
| 
 | 
 | ||||||
| 	<p class="error">{{ error }}</p> | 	<p class="error">{{ error }}</p> | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user