error mesasge on login pops up
This commit is contained in:
parent
22c397aebb
commit
a4ebdbc96c
@ -26,7 +26,7 @@
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div id="form-error" class="error"></div>
|
||||
<div id="login-error" class="error"></div>
|
||||
</div>
|
||||
</form>
|
||||
</body>
|
||||
|
@ -3,13 +3,10 @@ import { login } from "./services/users.service.js";
|
||||
document.getElementById("loginForm").addEventListener("submit", function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
document.getElementById("form-error").style.display = "none";
|
||||
|
||||
const emailOrUsername = document.getElementById("emailorusn").value;
|
||||
const password = document.getElementById("psw").value;
|
||||
|
||||
login(emailOrUsername, password)
|
||||
.then(response => {
|
||||
login(emailOrUsername, password).then((response) => {
|
||||
if(response.token && response.refreshToken){
|
||||
document.cookie = `auth-token=${response.token}; Path=/`;
|
||||
document.cookie = `refresh-token=${response.refreshToken}; Path=/`;
|
||||
@ -21,8 +18,8 @@ document.getElementById("loginForm").addEventListener("submit", function(event)
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
document.getElementById("form-error").innerText = error;
|
||||
document.getElementById("form-error").style.display = "block";
|
||||
document.getElementById("login-error").innerText = error;
|
||||
document.getElementById("login-error").style.display = "block";
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -6,19 +6,11 @@ export function get() {
|
||||
return request("GET",`/user/get`)
|
||||
}
|
||||
|
||||
export function login(usernameOrEmail, password) {
|
||||
return fetch(`${address}/user/login`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({ password: password, EmailOrUsrn: usernameOrEmail })
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
return("Request failed with HTTP code " + response.status);
|
||||
}
|
||||
return response.json();
|
||||
|
||||
export function login(emailOrUsrn, password){
|
||||
return request("POST", "/user/login", {
|
||||
emailOrUsrn,
|
||||
password,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ export async function request(method, path, body = null) {
|
||||
})
|
||||
.then(async response => {
|
||||
if (response.status === 401) {
|
||||
await getTokenByReferenceId(method, path, body);
|
||||
getTokenByReferenceId(method, path, body);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -45,11 +45,10 @@ export async function request(method, path, body = null) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function getTokenByReferenceId(method, path, body = null) {
|
||||
console.log("gtbri");
|
||||
export function getTokenByReferenceId(method, path, body = null) {
|
||||
var token = document.cookie.match(/\brefresh-token=([^;\s]+)/);
|
||||
if (token != null) {
|
||||
return await fetch(`${address}/user/refreshtoken/${token[1]}`, {
|
||||
return fetch(`${address}/user/refreshtoken/${token[1]}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
@ -60,7 +59,6 @@ export async function getTokenByReferenceId(method, path, body = null) {
|
||||
|
||||
document.cookie = `auth-token=${json.token}; Path=/`;
|
||||
document.cookie = `refresh-token=${json.refreshToken}; Path=/`;
|
||||
console.log(json.token);
|
||||
|
||||
return request(method, path, body);
|
||||
})
|
||||
@ -68,7 +66,6 @@ export async function getTokenByReferenceId(method, path, body = null) {
|
||||
location.href = "/login";
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export function logout() {
|
||||
|
Loading…
Reference in New Issue
Block a user