Skip to content

Conversation

@islandbitcoin
Copy link
Contributor

@islandbitcoin islandbitcoin commented Sep 16, 2025

Email-Only Authentication Implementation

  • New GraphQL mutations: newUserEmailRegistrationInitiate and newUserEmailRegistrationValidate for email-only account creation
  • Kratos integration: Successfully using email recovery flow for OTP delivery
  • Account creation: Fixed critical bug where accounts weren't being created after validation
  • Code cleanup: Removed all debug console.log statements

Key Changes Made

  1. Fixed validation logic - Changed from checking User existence to Account existence
  2. Proper account creation - Creates account with wallets when none exists
  3. Clean production code - Removed debug statements for production readiness

@islandbitcoin islandbitcoin requested a review from brh28 September 16, 2025 20:00
@islandbitcoin islandbitcoin self-assigned this Sep 16, 2025
@islandbitcoin islandbitcoin added the enhancement New feature or request label Sep 16, 2025
@islandbitcoin islandbitcoin force-pushed the feat/email-registration branch from 81894da to 66e733f Compare September 17, 2025 15:54
Copy link
Contributor

@brh28 brh28 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already the following definition in the graphql schema, which appears to the same or similar to what's being done in this PR:

  userEmailRegistrationInitiate(input: UserEmailRegistrationInitiateInput!): UserEmailRegistrationInitiatePayload!
  userEmailRegistrationValidate(input: UserEmailRegistrationValidateInput!): UserEmailRegistrationValidatePayload!

@islandbitcoin
Copy link
Contributor Author

There's already the following definition in the graphql schema, which appears to the same or similar to what's being done in this PR:

  userEmailRegistrationInitiate(input: UserEmailRegistrationInitiateInput!): UserEmailRegistrationInitiatePayload!
  userEmailRegistrationValidate(input: UserEmailRegistrationValidateInput!): UserEmailRegistrationValidatePayload!

These definitions do not allow for a email registration without an existing account. The choice was to modify these, to handle both cases (with account and without account) or create a new schema definition for new accounts.

  - New GraphQL mutations: newUserEmailRegistrationInitiate and newUserEmailRegistrationValidate for email-only account creation
  - Kratos integration: Successfully using email recovery flow for OTP delivery
  - Account creation: Fixed critical bug where accounts weren't being created after validation
  - Code cleanup: Removed all debug console.log statements

  ✅ Key Changes Made

  1. Fixed validation logic - Changed from checking User existence to Account existence
  2. Proper account creation - Creates account with wallets when none exists
  3. Clean production code - Removed debug statements for production readiness
@islandbitcoin islandbitcoin force-pushed the feat/email-registration branch from 66e733f to 90f293e Compare October 17, 2025 22:08
@islandbitcoin islandbitcoin requested a review from brh28 October 17, 2025 22:33
@islandbitcoin
Copy link
Contributor Author

@brh28 please review

// so that if one fails, the other is rolled back

// 1. Update user record with email (deviceId is preserved via spread)
const userUpdated = await UsersRepository().findById(userId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 60-65 can be consolidated to a single database update. The function would be something like:

addEmail: (userId, email) => db.updateOne( { userId }, { $set: { email })

userId: UserId
email: EmailAddress
}): Promise<Account | RepositoryError> => {
// TODO: ideally both 1. and 2. should be done in a transaction,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe there's a way to make this atomic unless we completely rewrite our data model


import { createAccountWithEmailIdentifier } from "@app/accounts"

export const createAccountFromEmailRegistrationPayload = async ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this function being called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nowhere! apparently its leftover from a previous attempt at getting this to work. Removed the file and the export reference

Copy link
Contributor

@brh28 brh28 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do a code walk through on this one? I'm having a hard time following

@brh28
Copy link
Contributor

brh28 commented Oct 30, 2025

Related to: #237

@islandbitcoin
Copy link
Contributor Author

@brh28 I think this is ready for a code review again, since we patched the orphaned accounts issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants