Login con email y password que devuelve un token
Publicado por Carlos (3 intervenciones) el 09/05/2021 18:35:42
Buenas tardes. Necesito crear en javascript una pantalla de login que pida email y password y devuelva un token y se conecte a una api. Después de mucho investigar (estoy aprendiendo), solo he conseguido este codigo, que me devuelve: error 404, a ver si alguien puede echarme una mano.. Gracias
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html>
<title> FORMULARIO ACCESO </title>
<body>
<h1>Datos</h1>
<form id="formulario" action="https://app.councilbox.com/graphql" method = "post">
<div>
<label>
<p>Email</p>
<input type="text" id="email" name="email" placeholder="email"/>
</label>
<label>
<p>Password</p>
<input type="password" id="password" name="password" placeholder="password"/>
</label>
<button type="submit">Acceso</button>
</div>
</form>
</body>
<script>
async function submit(){
const url = "https://app.councilbox.com/graphql";
const email= document.querySelector("email");
const password= document.querySelector("password");
const formulario = document.querySelector("formulario");
formEl.addEventListener("submit", async (e) => {
e.preventDefault();
});
let response = await fetch(url, {
method: "POST",
body: JSON.stringify({email,
password
}),
headers: {
"Content-Type": "application/json",
},
});
const json = await response.json();
console.log(json);
console.error(e);
alert("there as an error");
}
;
</script>
</html>
Valora esta pregunta


0