Skip to content

Conversation

@saenyakorn
Copy link
Member

Why did you create this PR

  • Because in some business, they required sign up / forgot password / change phone number with phone number

What did you do

  • Implement plugin API which contains 7 endpoints
  1. send sign up otp - to request OTP when sign up
  2. verify sign up otp - to verify and create a user
  3. send forgot password otp - to request otp when user want to forgot password
  4. verify forgot password otp - to verify if user is an owner of the phone number
  5. reset password - to receive token from verify forgot password, old password, and new password and reset the user password
  6. send change phone number otp - to request OTP when chaning phone number
  7. verify change phone number otp - to verify OTP and change the phone number

Screenshots / Recordings

  1. Sign up happy path and unhappy path
CleanShot.2568-08-28.at.17.33.47.mp4
  1. Forgot password happy path

  2. Forgot password unhappy path

  3. Change password happy path

  4. Change password unhappy path

Checklist

  • Self-reviewed your code
  • Wrote coverage tests
  • Added screenshots or recordings if applicable

@saenyakorn saenyakorn requested a review from Copilot August 29, 2025 06:57
@changeset-bot
Copy link

changeset-bot bot commented Aug 29, 2025

🦋 Changeset detected

Latest commit: 86f4bbf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@example/erp Patch
@genseki/next Minor
@genseki/plugins Minor
@genseki/react Minor
@example/ui-playground Patch
@genseki/prisma-generator Minor
@genseki/react-query Minor
@genseki/rest Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a comprehensive Phone Plugin API for authentication using phone numbers. The feature provides seven endpoints supporting phone-based sign-up, forgot password, and phone number change workflows with OTP verification.

  • Implements phone-based authentication with OTP verification for sign-up, password reset, and phone number changes
  • Adds type definitions and interfaces to support phone-based authentication flows
  • Updates Next.js resource handling with improved error handling and response validation

Reviewed Changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
packages/react/src/core/prisma.types.ts Updates Prisma type definitions from any to more specific Record<string, any>
packages/react/src/core/index.ts Exports MockPrismaClient type for external use
packages/plugins/src/phone/types.ts Defines TypeScript types and interfaces for phone plugin functionality
packages/plugins/src/phone/store.ts Implements PhoneStore class with database operations for phone authentication
packages/plugins/src/phone/service.ts Implements PhoneService class with business logic for phone authentication workflows
packages/plugins/src/phone/index.ts Creates API endpoints for phone authentication using the service layer
packages/plugins/src/phone/helper.ts Provides utility function for safe JSON parsing
packages/plugins/src/index.ts Exports phone plugin functionality
packages/plugins/package.json Adds new dependencies for the phone plugin
packages/next/src/resource.ts Improves error handling and response validation
examples/erp/prisma/schema.prisma Adds phone and phoneVerified fields to User model
examples/erp/prisma/migrations/20250828094031_add_phone_number/migration.sql Database migration for phone fields
examples/erp/http.rest HTTP test requests for phone API endpoints
examples/erp/genseki/plugins/phone.ts Implementation example of phone plugin usage
examples/erp/genseki/plugins/me.ts Plugin configuration for user profile functionality
examples/erp/genseki/config.tsx Updates app configuration to include phone plugin
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@saenyakorn saenyakorn requested a review from miello August 31, 2025 15:22
Comment on lines +58 to +60
onOtpVerify: async (payload) => {
return Math.random() < 0.5
},
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm quite not recommend using random for checking otp verify even in example application 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

Instead, we may have mock server to mock OTP verification which is a huge task. Maybe not in this PR

Comment on lines +212 to +219
const verifyStatus = await this.options.signUp
.onOtpVerify({
phone: data.phone,
token: verification.id,
pin: data.pin,
})
.then((result) => ok(result))
.catch((error) => err(error))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use fromPromise instead ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe like this

const result = await fromPromise(
  this.store.createSignUpVerification({
    id: otpResponse.value.token,
    refCode: otpResponse.value.refCode,
    value: {
      phone: data.phone,
      password: hashedPassword,
      data: rest as z.output<TSignUpBodySchema>,
      attempt: 0,
    },
    // TODO: Check the expiration time from config
    expiredAt: new Date(Date.now() + 5 * 60 * 1000), // 5 minutes
  }),
  R.identity()
)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, but the result is the same. I personally don't like fromPromise because of the indents

Copy link
Contributor

@miello miello left a comment

Choose a reason for hiding this comment

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

LGTM 🥳

@saenyakorn saenyakorn merged commit 23d5dcb into main Sep 1, 2025
1 check passed
@saenyakorn saenyakorn deleted the yu/feat/phone-plugin branch September 1, 2025 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants