Skip to content

Commit d77caed

Browse files
committed
chore(auth): clarify login form readiness guard
1 parent dfe8457 commit d77caed

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

packages/auth-service/src/__tests__/login-page.test.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,11 @@ function renderDefault(): string {
522522
}
523523

524524
describe('renderLoginPage email form readiness gate', () => {
525-
it('renders the email OTP form as not ready until JavaScript enables it', () => {
525+
it('renders the email OTP form without a readiness dataset marker', () => {
526526
const html = renderDefault()
527-
expect(html).toContain(
528-
'<form id="form-send-otp" data-epds-login-ready="false">',
529-
)
527+
expect(html).toContain('<form id="form-send-otp">')
528+
expect(html).not.toContain('data-epds-login-ready')
529+
expect(html).not.toContain('epdsLoginReady')
530530
})
531531

532532
it('renders the email submit button disabled with the existing label', () => {
@@ -536,17 +536,13 @@ describe('renderLoginPage email form readiness gate', () => {
536536
)
537537
})
538538

539-
it('marks the form ready and enables the button after handler setup', () => {
539+
it('enables the button after handler setup', () => {
540540
const html = renderDefault()
541541
const lastHandlerIdx = html.lastIndexOf("addEventListener('click'")
542-
const readyIdx = html.indexOf(
543-
"sendOtpForm.dataset.epdsLoginReady = 'true';",
544-
)
545-
const enableIdx = html.indexOf('sendOtpBtn.disabled = false;', readyIdx)
542+
const enableIdx = html.indexOf('sendOtpBtn.disabled = false;')
546543

547544
expect(lastHandlerIdx).toBeGreaterThan(0)
548-
expect(readyIdx).toBeGreaterThan(lastHandlerIdx)
549-
expect(enableIdx).toBeGreaterThan(readyIdx)
545+
expect(enableIdx).toBeGreaterThan(lastHandlerIdx)
550546
})
551547

552548
it('does not use a blind timeout for readiness', () => {

packages/auth-service/src/routes/login-page.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ export function renderLoginPage(opts: {
660660
661661
<!-- Step 1: Email entry (calls better-auth sendOtp) -->
662662
<div id="step-email" class="step-email${opts.initialStep === 'otp' ? ' hidden' : ''}">
663-
<form id="form-send-otp" data-epds-login-ready="false">
663+
<form id="form-send-otp">
664664
<div class="field">
665665
<label for="email">Enter your email address</label>
666666
<input type="email" id="email" name="email" required autofocus
@@ -1165,7 +1165,8 @@ export function renderLoginPage(opts: {
11651165
clearOtpBoxes();
11661166
});
11671167
1168-
sendOtpForm.dataset.epdsLoginReady = 'true';
1168+
// Enable only after the submit handler is installed. This avoids a race mostly
1169+
// seen in fast e2e runs where the button is clicked before JS is ready.
11691170
sendOtpBtn.disabled = false;
11701171
11711172
// Pillar 1: If login_hint was provided, the OTP step is already visible

0 commit comments

Comments
 (0)