Update index.html
Browse files- index.html +51 -103
index.html
CHANGED
|
@@ -1,112 +1,60 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 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 |
-
// π Check sign-in status on load
|
| 44 |
-
async function checkSignInStatus() {
|
| 45 |
-
const signedIn = await puter.auth.isSignedIn();
|
| 46 |
-
if (signedIn) {
|
| 47 |
-
const user = await puter.auth.getUser();
|
| 48 |
-
statusEl.textContent = `Signed in as ${user.username}`;
|
| 49 |
} else {
|
| 50 |
-
|
| 51 |
}
|
| 52 |
}
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
document.getElementById("sign-in").addEventListener("click", async () => {
|
| 58 |
-
try {
|
| 59 |
-
statusEl.textContent = "Signing in...";
|
| 60 |
-
const user = await puter.auth.signIn();
|
| 61 |
-
statusEl.textContent = `β
Signed in as ${user.username}`;
|
| 62 |
-
console.log("User:", user);
|
| 63 |
-
} catch (error) {
|
| 64 |
-
statusEl.textContent = "β Sign-in failed";
|
| 65 |
-
console.error("Sign-in error:", error);
|
| 66 |
-
}
|
| 67 |
-
});
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
messageDiv.classList.add("message");
|
| 74 |
-
if (isUser) messageDiv.classList.add("user-message");
|
| 75 |
-
messageDiv.textContent = msg;
|
| 76 |
-
messagesDiv.appendChild(messageDiv);
|
| 77 |
-
messagesDiv.scrollTop = messagesDiv.scrollHeight;
|
| 78 |
}
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
if (e.key === "Enter") sendMessage();
|
| 83 |
-
});
|
| 84 |
-
|
| 85 |
-
async function sendMessage() {
|
| 86 |
-
const input = document.getElementById("input-message");
|
| 87 |
-
const message = input.value.trim();
|
| 88 |
-
if (!message) return;
|
| 89 |
-
|
| 90 |
-
addMessage(message, true);
|
| 91 |
-
input.value = "";
|
| 92 |
-
|
| 93 |
-
messages.push({ role: "user", content: message });
|
| 94 |
-
|
| 95 |
-
try {
|
| 96 |
-
const response = await puter.ai.chat(messages);
|
| 97 |
-
const reply = response.message?.content || JSON.stringify(response);
|
| 98 |
-
addMessage(reply);
|
| 99 |
-
messages.push({ role: "assistant", content: reply });
|
| 100 |
-
} catch (err) {
|
| 101 |
-
addMessage("β οΈ Error connecting to AI. Check console.");
|
| 102 |
-
console.error("AI chat error:", err);
|
| 103 |
-
}
|
| 104 |
-
}
|
| 105 |
-
|
| 106 |
-
// π Optional: Show usage in console
|
| 107 |
-
puter.auth.getMonthlyUsage().then((usage) => {
|
| 108 |
-
console.log("Usage:", usage);
|
| 109 |
-
});
|
| 110 |
-
</script>
|
| 111 |
-
</body>
|
| 112 |
</html>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Puter Auth Demo</title>
|
| 7 |
+
<link rel="stylesheet" href="style.css">
|
| 8 |
+
<script src="https://js.puter.com/v2/"></script>
|
| 9 |
+
</head>
|
| 10 |
+
<body>
|
| 11 |
+
<div class="container">
|
| 12 |
+
<h1>Puter Authentication</h1>
|
| 13 |
+
<p class="desc">Sign in to your Puter account to continue</p>
|
| 14 |
+
|
| 15 |
+
<button id="sign-in">Sign In</button>
|
| 16 |
+
<pre id="output">Waiting for user action...</pre>
|
| 17 |
+
</div>
|
| 18 |
+
|
| 19 |
+
<script>
|
| 20 |
+
const output = document.getElementById('output');
|
| 21 |
+
const signInBtn = document.getElementById('sign-in');
|
| 22 |
+
|
| 23 |
+
function print(msg) {
|
| 24 |
+
output.innerText = msg;
|
| 25 |
+
console.log(msg);
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
async function signInWithRedirectFallback() {
|
| 29 |
+
try {
|
| 30 |
+
print("Attempting popup sign-in...");
|
| 31 |
+
const user = await puter.auth.signIn();
|
| 32 |
+
print("β
Signed in:\n" + JSON.stringify(user, null, 2));
|
| 33 |
+
return user;
|
| 34 |
+
} catch (err) {
|
| 35 |
+
if (err.message?.includes("popup")) {
|
| 36 |
+
print("β οΈ Popup blocked or unavailable. Trying redirect login...");
|
| 37 |
+
try {
|
| 38 |
+
await puter.auth.signIn({ mode: 'redirect' });
|
| 39 |
+
} catch (redirectErr) {
|
| 40 |
+
print("β Redirect sign-in failed:\n" + JSON.stringify(redirectErr));
|
| 41 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
} else {
|
| 43 |
+
print("β Sign-in error:\n" + JSON.stringify(err));
|
| 44 |
}
|
| 45 |
}
|
| 46 |
+
}
|
| 47 |
|
| 48 |
+
signInBtn.addEventListener('click', () => {
|
| 49 |
+
signInWithRedirectFallback();
|
| 50 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
(async () => {
|
| 53 |
+
const user = await puter.auth.getUser();
|
| 54 |
+
if (user) {
|
| 55 |
+
print("β
Already signed in:\n" + JSON.stringify(user, null, 2));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
}
|
| 57 |
+
})();
|
| 58 |
+
</script>
|
| 59 |
+
</body>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
</html>
|