<@U04UQ68083H> I want to have a unified login / re...
# ory-copilot
l
@chilly-king-10285 I want to have a unified login / registration flow with the “code” method. So that I display a page where a user enters their email - if they already have an account with me they can login otherwise they are sent to a page where they are prompted to register
b
A message from kapa.ai
Yes, you can implement a unified login/registration flow using the “code” (one-time code) method in Ory Kratos or Ory Network, but it requires building a custom UI and some backend logic. ### How it works - The user lands on a single authentication page and enters their email address. - Your backend checks if the email exists: - If the email exists, trigger the login flow with the code method. - If the email does not exist, trigger the registration flow with the code method. - The user receives a code via email and enters it to complete login or registration. This approach is confirmed as possible in an official Ory discussion, but it’s not available out-of-the-box—you need to orchestrate the flow yourself. The Ory team suggests: - Creating a custom UI that first asks for the email. - After submission, your backend determines if the email is registered. - Based on the result, you start either the login or registration flow using the code method. - Then, prompt the user for the code and complete the process accordingly. This is essentially a combination of the code-based login and registration flows, unified by your application logic and UI. The Ory self-service flows and the code method support this, but the orchestration is up to you. You may also want to configure the registration hook to automatically create a session after registration for a seamless experience [Unify sign-in and sign-in page to single input for passwordless "code" login](https://github.com/ory/kratos/discussions/4294). For more details on enabling and configuring the code method, see the official documentation: - [One-time code authentication](https://www.ory.sh/docs/kratos/passwordless/one-time-code) - [Custom email templates for code flows](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates) Summary: A unified login/registration flow with the code method is possible with Ory, but you need to implement the logic and UI to handle the distinction between login and registration after the user submits their email.