Authenticate user and password from another page

Asked

Viewed 334 times

-3

I need to create a form and send "POST" method the data to authenticate on another site. I would like to know how it is done, even pq when pressing the "Log in" button you have to access normally as if you had entered the site itself.

Thanks in advance.

2 answers

2

You can enter the login page of the other site in the form.

<form method="POST" action="https://seusite.com/site02login.php">
 <input type="email" name="email" id="email" placeholder="Email" />
 <input type="password" name="password" id="password" placeholder="Password" />
 <button type="submit">Acessar Conta</button>
<form>

Hence the https://seusite.com/site02login.php will receive the POST!

1

You can do this by using javascript’s own fetch or opting for lib as Xios. it’s not very difficult;

This is the HTML

<form method="POST">
   <input type="email" name="email" id="email" placeholder="Email" />
   <input type="password" name="password" id="password" placeholder="Password" />
   <button type="submit">Acessar Conta</button>
<form>

Javascript

const button = document.querySelector('button[type="submit"]');
const handleLogin = (event) => {
    event.preventDefault();

    const email = document.getElementById('email'),
          password = document.getElementById('password');
    fetch('http://myapi.com/api/v1/login', { email, password })
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.log(error))
}
button.addEventListener('click', handleLogin);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.