Looped sync works, but is slow. No retry or resiliency built in.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Auth Response</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Test Impersonation</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; margin: 2rem; }
|
||||
#banner { display:none; background:#ffcc00; padding:1rem; margin-bottom:1rem; font-weight:bold; }
|
||||
#form { display:flex; flex-direction:column; max-width:400px; }
|
||||
label { margin:0.5rem 0 0.2rem; }
|
||||
input { padding:0.5rem; font-size:1rem; }
|
||||
button { margin-top:1rem; padding:0.5rem; font-size:1rem; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="banner">⚠️ Impersonation Mode Active</div>
|
||||
|
||||
<h1>Test Impersonation</h1>
|
||||
<div id="form">
|
||||
<label for="targetInput">User ID or Email:</label>
|
||||
<input type="text" id="targetInput" placeholder="Enter user ID or email">
|
||||
<button id="impersonateBtn">Impersonate</button>
|
||||
<button id="returnBtn" style="display:none;">Return to Admin</button>
|
||||
<button id="goMainBtn" style="display:none;">Go to Main App</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const banner = document.getElementById('banner');
|
||||
const targetInput = document.getElementById('targetInput');
|
||||
const impersonateBtn = document.getElementById('impersonateBtn');
|
||||
const returnBtn = document.getElementById('returnBtn');
|
||||
const goMainBtn = document.getElementById('goMainBtn');
|
||||
|
||||
let originalToken = localStorage.getItem('pb_original_token') || localStorage.getItem('pb_token') || '';
|
||||
|
||||
impersonateBtn.addEventListener('click', async () => {
|
||||
const identifier = targetInput.value.trim();
|
||||
if (!identifier) return alert('Enter a user ID or email');
|
||||
if (!originalToken) return alert('You must be logged in as Admin/Superuser');
|
||||
|
||||
try {
|
||||
const res = await fetch('http://localhost:8081/api/impersonate', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + originalToken,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ targetUserIdentifier: identifier })
|
||||
});
|
||||
|
||||
if (!res.ok) return alert('Failed: ' + await res.text());
|
||||
|
||||
const data = await res.json();
|
||||
localStorage.setItem('pb_token', data.token);
|
||||
if (!localStorage.getItem('pb_original_token')) {
|
||||
localStorage.setItem('pb_original_token', originalToken);
|
||||
}
|
||||
|
||||
banner.style.display = 'block';
|
||||
returnBtn.style.display = 'inline-block';
|
||||
goMainBtn.style.display = 'inline-block';
|
||||
impersonateBtn.disabled = true;
|
||||
alert('Now impersonating ' + identifier);
|
||||
|
||||
} catch (err) { alert('Error: ' + err.message); }
|
||||
});
|
||||
|
||||
returnBtn.addEventListener('click', () => {
|
||||
const orig = localStorage.getItem('pb_original_token');
|
||||
if (!orig) return alert('Original token not found');
|
||||
localStorage.setItem('pb_token', orig);
|
||||
localStorage.removeItem('pb_original_token');
|
||||
banner.style.display = 'none';
|
||||
returnBtn.style.display = 'none';
|
||||
goMainBtn.style.display = 'none';
|
||||
impersonateBtn.disabled = false;
|
||||
alert('Returned to Admin session');
|
||||
});
|
||||
|
||||
goMainBtn.addEventListener('click', () => window.location.href = '/index.html');
|
||||
|
||||
if (localStorage.getItem('pb_original_token') && localStorage.getItem('pb_token') !== localStorage.getItem('pb_original_token')) {
|
||||
banner.style.display = 'block';
|
||||
returnBtn.style.display = 'inline-block';
|
||||
goMainBtn.style.display = 'inline-block';
|
||||
impersonateBtn.disabled = true;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user