openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

One time password does not work for patrons without existing accounts

Open seabelis opened this issue 1 month ago • 4 comments

Problem

Patrons trying to log in for the first time expect the one time password option to work. However, it only works for patrons with existing accounts.

Reproducing the bug

  1. Go to ...https://openlibrary.org/account/login
  2. Do ...enter an unregistered email address
  • Expected behavior: Patron should be prompted to create an account.
  • Actual behavior: Message indicates a one-time password has been sent.

Context

  • Browser (Chrome, Safari, Firefox, etc):
  • OS (Windows, Mac, etc):
  • Logged in (Y/N):
  • Environment (prod, dev, local): prod

Breakdown

Implementation Details (for maintainers)

Requirements Checklist

  • [ ]

Related files

Stakeholders


Instructions for Contributors

  • Please run these commands to ensure your repository is up to date before creating a new branch to work on this issue and each time after pushing code to Github, because the pre-commit bot may add commits to your PRs upstream.

seabelis avatar Oct 21 '26 17:10 seabelis

Hi! I'd like to look into this issue. I'll trace the one-time password login flow and check how the application handles email addresses that don't have an existing account. Then I'll investigate where the signup prompt should be triggered.

iamshravanijadhav avatar Oct 22 '26 00:10 iamshravanijadhav

I'd like to work on this issue. Plan: Before calling issue_otp inside account_login_otp_issue.POST we call InternetArchiveAccount.get(email) to make sure the account exists. If it returns nothing we respond with an error saying account not found. And we handle the error case in OpenLibraryOTP handle email submit to inform the user they need to register and add the button

Testing plan: Add unit tests for /account/otp/issue

I’d be happy to implement this change and submit a PR. Could a maintainer please confirm that I can take this issue?

menteMaesta avatar Oct 22 '26 00:10 menteMaesta

Hi! I'd like to request assignment for this issue. I see @iamshravanijadhav and @menteMaesta asked earlier, so I'm happy to defer to whatever the maintainers decide, or to split the work if that's useful.

My understanding of the problem When a patron enters an email with no account, account_login_otp_issue.POST (openlibrary/plugins/upstream/account.py) calls InternetArchiveAccount.issue_otp() and returns {"success": true} whenever xauthn reports success. _handleEmailSubmit in OpenLibraryOTP.js then moves to the "We sent a 6-digit code" step, so the patron waits for an email that never usefully arrives. Neither side checks that an account exists.

Proposed solution

  1. Backend (account.py, account_login_otp_issue.POST): before issuing the OTP, check whether an Internet Archive account exists for the email. If not, return {"error": "account_not_found"}. There is already an account_not_found message in get_login_error, so the wording stays consistent with password login.
  2. Distinguish "not found" from "service failed": InternetArchiveAccount.get() returns None in both cases, so an xauthn outage would show as "no account found". I'd either add a small helper that surfaces the difference or only treat a successful response with no account as "not found". Real failures keep returning otp_issue_failed.
  3. Frontend (OpenLibraryOTP.js, _handleEmailSubmit): handle account_not_found by staying on the email step and showing a message with a "Sign up" link to /account/create. _issueError is rendered with textContent, so a link needs a separate state field and element.
  4. Resend: _handleResend calls the same endpoint, so it should keep working, but I'll check that it can't hit the not-found path unexpectedly.
  5. Tests: unit tests for /account/login/otp/issue covering an existing account, an unknown email, xauthn failure, and rate limiting (429 must still work). If the repo has JS tests for this component, I'll add one for the new error state.

Files I expect to change

  • openlibrary/plugins/upstream/account.py
  • openlibrary/components/lit/OpenLibraryOTP.js
  • possibly openlibrary/accounts/model.py (if a helper is needed)
  • the existing tests for account.py under openlibrary/plugins/upstream/tests

Questions

  1. Does xauthn's issue_otp have a way to report "unknown email" directly? That would avoid a second call to info.
  2. This reveals whether an email is registered. Password login and /account/validate already do, so I think it's consistent, but is that acceptable for the OTP flow?
  3. Should the sign-up link prefill the entered email, if the create form supports it?

I haven't started coding and will wait for assignment. Thanks!

Krishkumarchhabra25 avatar Oct 22 '26 09:10 Krishkumarchhabra25

It can go to @iamshravanijadhav since she was first

menteMaesta avatar Oct 22 '26 21:10 menteMaesta