feat: convert change-email from modal to standalone page + Stripe customer.updated webhook
All checks were successful
Deploy to Production / Deploy to Server (push) Successful in 1m8s
All checks were successful
Deploy to Production / Deploy to Server (push) Successful in 1m8s
- Add /change-email as a proper standalone page (public/src/change-email.html) with API key input, new email input, verification code flow, and success state - Update footer partial: change "/#change-email" link to "/change-email" on all pages - Remove email change modal HTML and hash-handler JS from index page source - Add /change-email to sitemap.xml - Rebuild all HTML files via build-html.cjs - Add updateEmailByCustomer() to src/services/keys.ts - Add customer.updated webhook handler in src/routes/billing.ts to sync email changes made via Stripe dashboard back to DocFast
This commit is contained in:
parent
5099bae41f
commit
8f3b1a9660
12 changed files with 674 additions and 121 deletions
293
public/src/change-email.html
Normal file
293
public/src/change-email.html
Normal file
|
|
@ -0,0 +1,293 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Change Email — DocFast</title>
|
||||
<meta name="description" content="Change the email address associated with your DocFast API key.">
|
||||
<link rel="canonical" href="https://docfast.dev/change-email">
|
||||
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>⚡</text></svg>">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
|
||||
{{> styles_base}}
|
||||
<style>
|
||||
.change-email-wrap {
|
||||
max-width: 480px;
|
||||
margin: 80px auto 60px;
|
||||
padding: 0 24px;
|
||||
}
|
||||
.change-email-card {
|
||||
background: var(--card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 16px;
|
||||
padding: 40px;
|
||||
}
|
||||
.change-email-card h1 {
|
||||
font-size: 1.6rem;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.change-email-card .subtitle {
|
||||
color: var(--muted);
|
||||
margin-bottom: 28px;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
.ce-field {
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
.ce-field label {
|
||||
display: block;
|
||||
font-size: 0.85rem;
|
||||
color: var(--muted);
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.ce-field input {
|
||||
width: 100%;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--bg);
|
||||
color: var(--fg);
|
||||
border-radius: 8px;
|
||||
font-size: 0.9rem;
|
||||
font-family: inherit;
|
||||
box-sizing: border-box;
|
||||
transition: border-color 0.15s;
|
||||
}
|
||||
.ce-field input:focus {
|
||||
outline: none;
|
||||
border-color: var(--accent);
|
||||
}
|
||||
.ce-field input.monospace {
|
||||
font-family: monospace;
|
||||
}
|
||||
.ce-field input.code-input {
|
||||
font-family: monospace;
|
||||
font-size: 1.4rem;
|
||||
letter-spacing: 0.3em;
|
||||
text-align: center;
|
||||
padding: 14px;
|
||||
}
|
||||
.ce-btn {
|
||||
width: 100%;
|
||||
margin-top: 8px;
|
||||
}
|
||||
.ce-error {
|
||||
background: rgba(239,68,68,0.1);
|
||||
border: 1px solid rgba(239,68,68,0.3);
|
||||
color: #f87171;
|
||||
border-radius: 8px;
|
||||
padding: 10px 14px;
|
||||
font-size: 0.875rem;
|
||||
margin-bottom: 16px;
|
||||
display: none;
|
||||
}
|
||||
.ce-hint {
|
||||
margin-top: 14px;
|
||||
color: var(--muted);
|
||||
font-size: 0.8rem;
|
||||
text-align: center;
|
||||
}
|
||||
.ce-loading {
|
||||
text-align: center;
|
||||
padding: 20px 0;
|
||||
}
|
||||
.ce-success {
|
||||
text-align: center;
|
||||
padding: 10px 0;
|
||||
}
|
||||
.ce-success .success-icon {
|
||||
font-size: 3rem;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.ce-success h2 {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.ce-success p {
|
||||
color: var(--muted);
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
.step { display: none; }
|
||||
.step.active { display: block; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
{{> nav}}
|
||||
|
||||
<div class="change-email-wrap">
|
||||
<div class="change-email-card">
|
||||
|
||||
<!-- Step 1: Enter API key + new email -->
|
||||
<div class="step active" id="ceStepInitial">
|
||||
<h1>Change Email</h1>
|
||||
<p class="subtitle">Enter your API key and new email address.</p>
|
||||
<div class="ce-error" id="ceError"></div>
|
||||
<div class="ce-field">
|
||||
<label for="ceApiKey">Your API key</label>
|
||||
<input type="text" id="ceApiKey" class="monospace" placeholder="df_free_... or df_pro_..." required autocomplete="off" spellcheck="false">
|
||||
</div>
|
||||
<div class="ce-field">
|
||||
<label for="ceNewEmail">New email address</label>
|
||||
<input type="email" id="ceNewEmail" placeholder="new.email@example.com" required>
|
||||
</div>
|
||||
<button class="btn btn-primary ce-btn" id="ceSendBtn">Send Verification Code →</button>
|
||||
<p class="ce-hint">A 6-digit code will be sent to your new email address</p>
|
||||
</div>
|
||||
|
||||
<!-- Step 2: Loading -->
|
||||
<div class="step" id="ceStepLoading">
|
||||
<div class="ce-loading">
|
||||
<div class="spinner"></div>
|
||||
<p style="color:var(--muted);margin:12px 0 0">Sending verification code…</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Step 3: Enter code -->
|
||||
<div class="step" id="ceStepVerify">
|
||||
<h1>Check your inbox</h1>
|
||||
<p class="subtitle">We sent a 6-digit code to <strong id="ceEmailDisplay"></strong></p>
|
||||
<div class="ce-error" id="ceVerifyError"></div>
|
||||
<div class="ce-field">
|
||||
<label for="ceCode">Verification code</label>
|
||||
<input type="text" id="ceCode" class="code-input" placeholder="123456" maxlength="6" pattern="[0-9]{6}" inputmode="numeric" required>
|
||||
</div>
|
||||
<button class="btn btn-primary ce-btn" id="ceVerifyBtn">Verify →</button>
|
||||
<p class="ce-hint">Code expires in 15 minutes</p>
|
||||
</div>
|
||||
|
||||
<!-- Step 4: Success -->
|
||||
<div class="step" id="ceStepSuccess">
|
||||
<div class="ce-success">
|
||||
<div class="success-icon">✅</div>
|
||||
<h2>Email updated!</h2>
|
||||
<p>Your account email has been changed to <strong id="ceSuccessEmail"></strong></p>
|
||||
<a href="/" class="btn btn-primary">Back to Home →</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{> footer}}
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
var _apiKey = '';
|
||||
var _newEmail = '';
|
||||
|
||||
function showStep(id) {
|
||||
['ceStepInitial','ceStepLoading','ceStepVerify','ceStepSuccess'].forEach(function(s) {
|
||||
var el = document.getElementById(s);
|
||||
if (el) el.classList.remove('active');
|
||||
});
|
||||
var target = document.getElementById(id);
|
||||
if (target) target.classList.add('active');
|
||||
}
|
||||
|
||||
function showError(elId, msg) {
|
||||
var el = document.getElementById(elId);
|
||||
if (!el) return;
|
||||
el.textContent = msg;
|
||||
el.style.display = 'block';
|
||||
}
|
||||
|
||||
function hideError(elId) {
|
||||
var el = document.getElementById(elId);
|
||||
if (el) el.style.display = 'none';
|
||||
}
|
||||
|
||||
async function handleSend() {
|
||||
var apiKey = document.getElementById('ceApiKey').value.trim();
|
||||
var newEmail = document.getElementById('ceNewEmail').value.trim();
|
||||
|
||||
hideError('ceError');
|
||||
|
||||
if (!apiKey) {
|
||||
showError('ceError', 'Please enter your API key.');
|
||||
return;
|
||||
}
|
||||
if (!newEmail || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(newEmail)) {
|
||||
showError('ceError', 'Please enter a valid email address.');
|
||||
return;
|
||||
}
|
||||
|
||||
var btn = document.getElementById('ceSendBtn');
|
||||
btn.disabled = true;
|
||||
showStep('ceStepLoading');
|
||||
|
||||
try {
|
||||
var res = await fetch('/v1/email-change', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ apiKey: apiKey, newEmail: newEmail })
|
||||
});
|
||||
var data = await res.json();
|
||||
|
||||
if (!res.ok) {
|
||||
showStep('ceStepInitial');
|
||||
showError('ceError', data.error || 'Something went wrong. Please try again.');
|
||||
btn.disabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_apiKey = apiKey;
|
||||
_newEmail = newEmail;
|
||||
document.getElementById('ceEmailDisplay').textContent = newEmail;
|
||||
showStep('ceStepVerify');
|
||||
document.getElementById('ceCode').focus();
|
||||
} catch (err) {
|
||||
showStep('ceStepInitial');
|
||||
showError('ceError', 'Network error. Please try again.');
|
||||
btn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleVerify() {
|
||||
var code = document.getElementById('ceCode').value.trim();
|
||||
hideError('ceVerifyError');
|
||||
|
||||
if (!code || !/^\d{6}$/.test(code)) {
|
||||
showError('ceVerifyError', 'Please enter the 6-digit code.');
|
||||
return;
|
||||
}
|
||||
|
||||
var btn = document.getElementById('ceVerifyBtn');
|
||||
btn.disabled = true;
|
||||
|
||||
try {
|
||||
var res = await fetch('/v1/email-change/verify', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ apiKey: _apiKey, newEmail: _newEmail, code: code })
|
||||
});
|
||||
var data = await res.json();
|
||||
|
||||
if (!res.ok) {
|
||||
showError('ceVerifyError', data.error || 'Verification failed. Please try again.');
|
||||
btn.disabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
document.getElementById('ceSuccessEmail').textContent = data.newEmail || _newEmail;
|
||||
showStep('ceStepSuccess');
|
||||
} catch (err) {
|
||||
showError('ceVerifyError', 'Network error. Please try again.');
|
||||
btn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
document.getElementById('ceSendBtn').addEventListener('click', handleSend);
|
||||
document.getElementById('ceVerifyBtn').addEventListener('click', handleVerify);
|
||||
|
||||
// Allow Enter key in inputs
|
||||
document.getElementById('ceNewEmail').addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Enter') handleSend();
|
||||
});
|
||||
document.getElementById('ceCode').addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Enter') handleVerify();
|
||||
});
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -219,64 +219,7 @@
|
|||
</div>
|
||||
|
||||
|
||||
<!-- Email Change Modal -->
|
||||
<div class="modal-overlay" id="emailChangeModal" role="dialog" aria-modal="true" aria-label="Change email">
|
||||
<div class="modal">
|
||||
<button class="close" id="btn-close-email-change" aria-label="Close">×</button>
|
||||
|
||||
<div id="emailChangeInitial" class="active">
|
||||
<h2>Change your email</h2>
|
||||
<p>Enter your API key and new email address.</p>
|
||||
<div class="signup-error" id="emailChangeError"></div>
|
||||
<label for="emailChangeApiKey" class="sr-only">Your API key</label>
|
||||
<input type="text" id="emailChangeApiKey" placeholder="Your API key (df_free_... or df_pro_...)" style="width:100%;padding:12px;border:1px solid var(--border);background:var(--bg);color:var(--fg);border-radius:8px;font-size:0.9rem;margin-bottom:12px;font-family:monospace;" required>
|
||||
<label for="emailChangeNewEmail" class="sr-only">New email address</label>
|
||||
<input type="email" id="emailChangeNewEmail" placeholder="new.email@example.com" style="width:100%;padding:12px;border:1px solid var(--border);background:var(--bg);color:var(--fg);border-radius:8px;font-size:0.9rem;margin-bottom:16px;" required>
|
||||
<button class="btn btn-primary" style="width:100%" id="emailChangeBtn">Send Verification Code →</button>
|
||||
<p style="margin-top:16px;color:var(--muted);font-size:0.8rem;text-align:center;">A verification code will be sent to your new email</p>
|
||||
</div>
|
||||
|
||||
<div id="emailChangeLoading">
|
||||
<div class="spinner"></div>
|
||||
<p style="color:var(--muted);margin:0">Sending verification code…</p>
|
||||
</div>
|
||||
|
||||
<div id="emailChangeVerify">
|
||||
<h2>Enter verification code</h2>
|
||||
<p>We sent a 6-digit code to <strong id="emailChangeEmailDisplay"></strong></p>
|
||||
<div class="signup-error" id="emailChangeVerifyError"></div>
|
||||
<label for="emailChangeCode" class="sr-only">Verification code</label>
|
||||
<input type="text" id="emailChangeCode" placeholder="123456" maxlength="6" pattern="[0-9]{6}" inputmode="numeric" style="width:100%;padding:14px;border:1px solid var(--border);background:var(--bg);color:var(--fg);border-radius:8px;font-size:1.4rem;letter-spacing:0.3em;text-align:center;margin-bottom:16px;font-family:monospace;" required>
|
||||
<button class="btn btn-primary" style="width:100%" id="emailChangeVerifyBtn">Verify →</button>
|
||||
<p style="margin-top:16px;color:var(--muted);font-size:0.8rem;text-align:center;">Code expires in 15 minutes</p>
|
||||
</div>
|
||||
|
||||
<div id="emailChangeResult">
|
||||
<h2>✅ Email updated!</h2>
|
||||
<p>Your account email has been changed to <strong id="emailChangeNewDisplay"></strong></p>
|
||||
<p style="margin-top:20px;color:var(--muted);font-size:0.9rem;"><a href="/docs">Read the docs →</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/app.js"></script>
|
||||
|
||||
<script>
|
||||
// BUG-068: Open change-email modal when navigating to /#change-email
|
||||
(function() {
|
||||
function handleHashModal() {
|
||||
if (window.location.hash === '#change-email') {
|
||||
if (typeof openEmailChange === 'function') {
|
||||
openEmailChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', handleHashModal);
|
||||
} else {
|
||||
handleHashModal();
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue