One time password does not work for patrons without existing accounts
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
- Go to ...https://openlibrary.org/account/login
- 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.
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.
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?
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
- 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 anaccount_not_foundmessage inget_login_error, so the wording stays consistent with password login. - Distinguish "not found" from "service failed":
InternetArchiveAccount.get()returnsNonein 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 returningotp_issue_failed. - Frontend (
OpenLibraryOTP.js,_handleEmailSubmit): handleaccount_not_foundby staying on the email step and showing a message with a "Sign up" link to/account/create._issueErroris rendered withtextContent, so a link needs a separate state field and element. - Resend:
_handleResendcalls the same endpoint, so it should keep working, but I'll check that it can't hit the not-found path unexpectedly. - Tests: unit tests for
/account/login/otp/issuecovering 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.pyopenlibrary/components/lit/OpenLibraryOTP.js- possibly
openlibrary/accounts/model.py(if a helper is needed) - the existing tests for
account.pyunderopenlibrary/plugins/upstream/tests
Questions
- Does xauthn's
issue_otphave a way to report "unknown email" directly? That would avoid a second call toinfo. - This reveals whether an email is registered. Password login and
/account/validatealready do, so I think it's consistent, but is that acceptable for the OTP flow? - 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!
It can go to @iamshravanijadhav since she was first