<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@deflectbot/deflect-sdk@latest/dist/index.min.js"></script>
</head>
<body>
<form id="loginForm">
<input type="email" name="email" placeholder="Email" required />
<input type="password" name="password" placeholder="Password" required />
<button type="submit">Login</button>
</form>
<script>
// 1. Configure Deflect
Deflect.configure({
actionId: "YOUR_ACTION_ID",
});
// 2. Handle form submission
document
.getElementById("loginForm")
.addEventListener("submit", async (e) => {
e.preventDefault();
try {
// Get token from Deflect
const token = await Deflect.getToken();
// Make your API request with the token
const formData = new FormData(e.target);
const response = await fetch("/api/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
email: formData.get("email"),
password: formData.get("password"),
deflect_token: token,
}),
});
const result = await response.json();
console.log("Login result:", result);
} catch (error) {
console.error("Error:", error);
}
});
</script>
</body>
</html>