|
5 | 5 | <div class="text-5xl text-green-500 mb-5">✓</div> |
6 | 6 | <h1 class="text-gray-800 mb-5 text-2xl font-semibold">Authentication Successful</h1> |
7 | 7 |
|
8 | | - <p class="mb-5">Your API token has been generated for the Chrome extension:</p> |
| 8 | + <p class="mb-5">Your user email for the Chrome extension:</p> |
9 | 9 |
|
10 | 10 | <div class="bg-gray-50 border-2 border-dashed border-gray-300 rounded-lg p-5 my-5 break-all font-mono text-sm min-h-15 flex items-center justify-center"> |
11 | | - <div id="token-display" data-token="<%= current_user.email %>" class="text-gray-500 italic"> |
12 | | - <% if current_user.email %> |
13 | | - Loading token... |
14 | | - <% else %> |
15 | | - No token available. Please try again. |
16 | | - <% end %> |
| 11 | + <div id="token-display" data-token="<%= current_user&.email %>" class="text-sky-600 font-semibold"> |
| 12 | + <%= current_user&.email || 'No email available. Please try again.' %> |
17 | 13 | </div> |
18 | 14 | </div> |
19 | 15 |
|
20 | | - <button id="copy-btn" class="bg-sky-600 text-white border-none py-2 px-5 rounded cursor-pointer mt-4 text-sm disabled:bg-gray-400 disabled:cursor-not-allowed hover:bg-sky-700" disabled>Copy Token</button> |
21 | | - |
22 | 16 | <div class="text-gray-600 text-sm leading-relaxed mt-5"> |
23 | 17 | <strong>Instructions:</strong><br> |
24 | | - 1. The token above will be automatically captured by your Chrome extension<br> |
25 | | - 2. If using manually, copy the token and paste it into your extension<br> |
26 | | - 3. You can safely close this window after the token is captured |
| 18 | + Your email above will be automatically captured by your Chrome extension.<br> |
| 19 | + You can safely close this window after the email is captured. |
27 | 20 | </div> |
28 | | - |
29 | | - <div class="bg-yellow-50 border border-yellow-200 rounded p-4 mt-5 text-yellow-700 text-sm"> |
30 | | - <strong>Note:</strong> This window will automatically close in 10 seconds, or you can close it manually once the extension has captured the token. |
| 21 | + <!-- Debug info (remove in production) --> |
| 22 | + <div class="bg-gray-100 border border-gray-300 rounded p-3 mt-3 text-xs text-gray-600"> |
| 23 | + <strong>Debug:</strong> User: <%= current_user&.email || 'NOT AUTHENTICATED' %> | |
| 24 | + Session: <%= session[:user_id] || 'NO SESSION' %> |
31 | 25 | </div> |
32 | 26 | </div> |
33 | 27 | </div> |
34 | 28 |
|
35 | 29 | <script> |
36 | | - // Extract token from data attribute |
37 | | - function extractToken() { |
38 | | - const tokenDisplay = document.getElementById('token-display'); |
39 | | - const token = tokenDisplay.getAttribute('data-token'); |
40 | | - return token && token.length > 0 ? token : null; |
41 | | - } |
42 | | - |
43 | | - // Display the token |
44 | | - function displayToken() { |
45 | | - const token = extractToken(); |
46 | | - const tokenDisplay = document.getElementById('token-display'); |
47 | | - const copyBtn = document.getElementById('copy-btn'); |
48 | | - |
49 | | - if (token) { |
50 | | - tokenDisplay.textContent = token; |
51 | | - tokenDisplay.className = 'text-sky-600 font-semibold'; |
52 | | - copyBtn.disabled = false; |
53 | | - |
54 | | - // Post message to parent window (for Chrome extension) |
55 | | - if (window.opener) { |
56 | | - window.opener.postMessage({ |
57 | | - type: 'FACK_AUTH_TOKEN', |
58 | | - token: token, |
59 | | - success: true |
60 | | - }, '*'); |
61 | | - } |
62 | | - |
63 | | - // Also try posting to parent frame |
64 | | - if (window.parent && window.parent !== window) { |
65 | | - window.parent.postMessage({ |
66 | | - type: 'FACK_AUTH_TOKEN', |
67 | | - token: token, |
68 | | - success: true |
69 | | - }, '*'); |
70 | | - } |
71 | | - } else { |
72 | | - tokenDisplay.textContent = 'No token found. Please try again.'; |
73 | | - tokenDisplay.className = 'text-gray-500 italic'; |
74 | | - } |
75 | | - } |
76 | | - |
77 | | - // Copy token to clipboard |
78 | | - function copyToken() { |
79 | | - const token = extractToken(); |
80 | | - if (token) { |
81 | | - navigator.clipboard.writeText(token).then(() => { |
82 | | - const btn = document.getElementById('copy-btn'); |
83 | | - const originalText = btn.textContent; |
84 | | - btn.textContent = 'Copied!'; |
85 | | - btn.className = btn.className.replace('bg-sky-600', 'bg-green-500').replace('hover:bg-sky-700', ''); |
86 | | - |
87 | | - setTimeout(() => { |
88 | | - btn.textContent = originalText; |
89 | | - btn.className = btn.className.replace('bg-green-500', 'bg-sky-600') + ' hover:bg-sky-700'; |
90 | | - }, 2000); |
91 | | - }).catch(err => { |
92 | | - console.error('Could not copy token:', err); |
93 | | - // Fallback: select text |
94 | | - const tokenDisplay = document.getElementById('token-display'); |
95 | | - const range = document.createRange(); |
96 | | - range.selectNode(tokenDisplay); |
97 | | - window.getSelection().removeAllRanges(); |
98 | | - window.getSelection().addRange(range); |
99 | | - }); |
100 | | - } |
101 | | - } |
102 | | - |
103 | | - // Auto-close window after delay |
104 | | - function scheduleAutoClose() { |
105 | | - setTimeout(() => { |
106 | | - if (window.opener || window.parent !== window) { |
| 30 | + console.log('Auth page loaded - email should be captured by Chrome extension content script'); |
| 31 | + console.log('Email in data-token:', document.getElementById('token-display')?.getAttribute('data-token')); |
| 32 | + |
| 33 | + // Auto-close window after extension captures token |
| 34 | + setTimeout(() => { |
| 35 | + console.log('Auto-closing window...'); |
| 36 | + if (window.opener || window.parent !== window) { |
| 37 | + try { |
107 | 38 | window.close(); |
| 39 | + } catch (e) { |
| 40 | + console.log('Could not close window automatically'); |
108 | 41 | } |
109 | | - }, 10000); // 10 seconds |
110 | | - } |
111 | | - |
112 | | - // Initialize |
113 | | - document.addEventListener('DOMContentLoaded', () => { |
114 | | - displayToken(); |
115 | | - scheduleAutoClose(); |
116 | | - |
117 | | - document.getElementById('copy-btn').addEventListener('click', copyToken); |
118 | | - |
119 | | - // Listen for messages from Chrome extension |
120 | | - window.addEventListener('message', (event) => { |
121 | | - if (event.data.type === 'FACK_TOKEN_CAPTURED') { |
122 | | - // Extension has captured the token, can close window |
123 | | - setTimeout(() => window.close(), 1000); |
124 | | - } |
125 | | - }); |
126 | | - }); |
| 42 | + } |
| 43 | + }, 5000); // Reduced to 5 seconds |
127 | 44 | </script> |
0 commit comments