File size: 1,461 Bytes
5490769
 
6417b9c
 
 
abcc5a1
6417b9c
 
 
 
 
 
 
abcc5a1
6417b9c
 
 
 
 
 
 
 
 
 
 
 
abcc5a1
6417b9c
abcc5a1
 
6417b9c
abcc5a1
8b2178b
6417b9c
8b2178b
6417b9c
abcc5a1
6417b9c
d1a506d
abcc5a1
6417b9c
 
 
 
abcc5a1
 
d1a506d
6417b9c
 
 
d1a506d
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 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();
    });

    // Check if already signed in (after redirect)
    (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>