|
|
<!DOCTYPE html> |
|
|
<html lang="en"> |
|
|
<head> |
|
|
<meta charset="UTF-8" /> |
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
|
<title>Puter Auth (Redirect Safe)</title> |
|
|
<link rel="stylesheet" href="style.css"> |
|
|
<script src="https://js.puter.com/v2/"></script> |
|
|
</head> |
|
|
<body> |
|
|
<div class="container"> |
|
|
<h1>Puter Authentication</h1> |
|
|
<p class="desc">Sign in to your Puter account to continue</p> |
|
|
<button id="sign-in">Sign In with Puter</button> |
|
|
<pre id="output">Waiting for user action...</pre> |
|
|
</div> |
|
|
|
|
|
<script> |
|
|
const output = document.getElementById('output'); |
|
|
const signInBtn = document.getElementById('sign-in'); |
|
|
|
|
|
function print(msg) { |
|
|
output.innerText = msg; |
|
|
console.log(msg); |
|
|
} |
|
|
|
|
|
async function trySignIn() { |
|
|
try { |
|
|
print("Redirecting to Puter sign-in..."); |
|
|
await puter.auth.signIn({ mode: "redirect" }); |
|
|
} catch (err) { |
|
|
print("❌ Redirect sign-in failed:\n" + JSON.stringify(err)); |
|
|
} |
|
|
} |
|
|
|
|
|
signInBtn.addEventListener('click', () => { |
|
|
trySignIn(); |
|
|
}); |
|
|
|
|
|
|
|
|
(async () => { |
|
|
const user = await puter.auth.getUser(); |
|
|
if (user) { |
|
|
print("✅ Already signed in:\n" + JSON.stringify(user, null, 2)); |
|
|
document.querySelector('.desc').innerText = `Welcome, ${user.username}!`; |
|
|
signInBtn.style.display = "none"; |
|
|
} |
|
|
})(); |
|
|
</script> |
|
|
</body> |
|
|
</html> |
|
|
|