File size: 2,191 Bytes
5383ef0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Signing in…</title>
  <style>
    body { background: #0d0e11; color: #e8eaf0; font-family: system-ui, sans-serif;
      display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; }
    .box { text-align: center; }
    .spinner { width: 32px; height: 32px; border: 3px solid rgba(229,200,70,0.2);
      border-top-color: #e5c846; border-radius: 50%; animation: spin 0.8s linear infinite;
      margin: 0 auto 16px; }
    @keyframes spin { to { transform: rotate(360deg); } }
  </style>
</head>
<body>
  <div class="box">
    <div class="spinner"></div>
    <p>Completing sign-in…</p>
  </div>
  <script>
    // Extract tokens from URL hash (Supabase implicit flow) or search params
    function getTokens() {
      const hash   = new URLSearchParams(location.hash.replace('#', ''));
      const search = new URLSearchParams(location.search);
      return {
        access_token:  hash.get('access_token')  || search.get('access_token'),
        refresh_token: hash.get('refresh_token') || search.get('refresh_token'),
        error:         hash.get('error')         || search.get('error'),
        error_desc:    hash.get('error_description') || search.get('error_description'),
      };
    }

    const tokens = getTokens();

    if (tokens.error) {
      document.querySelector('p').textContent = 'Sign-in error: ' + (tokens.error_desc || tokens.error);
    } else if (tokens.access_token) {
      // Post to opener (main tab) and close
      if (window.opener && !window.opener.closed) {
        window.opener.postMessage({
          type: 'oauth:callback',
          access_token:  tokens.access_token,
          refresh_token: tokens.refresh_token,
        }, location.origin);
        window.close();
      } else {
        // No opener — redirect to main page with params
        const p = new URLSearchParams({ oauth: '1', t: tokens.access_token, r: tokens.refresh_token || '' });
        location.replace('/?' + p.toString());
      }
    } else {
      document.querySelector('p').textContent = 'No token received. Close this window.';
    }
  </script>
</body>
</html>