in packages/better-auth/src/plugins/phone-number/index.ts [382:518]
verifyPhoneNumber: createAuthEndpoint(
"/phone-number/verify",
{
method: "POST",
body: z.object({
/**
* Phone number
*/
phoneNumber: z.string({
description: "Phone number to verify",
}),
/**
* OTP code
*/
code: z.string({
description: "OTP code",
}),
/**
* Disable session creation after verification
* @default false
*/
disableSession: z
.boolean({
description: "Disable session creation after verification",
})
.optional(),
/**
* This checks if there is a session already
* and updates the phone number with the provided
* phone number
*/
updatePhoneNumber: z
.boolean({
description:
"Check if there is a session and update the phone number",
})
.optional(),
}),
metadata: {
openapi: {
summary: "Verify phone number",
description: "Use this endpoint to verify phone number",
responses: {
"200": {
description: "Phone number verified successfully",
content: {
"application/json": {
schema: {
type: "object",
properties: {
status: {
type: "boolean",
description:
"Indicates if the verification was successful",
enum: [true],
},
token: {
type: "string",
nullable: true,
description:
"Session token if session is created, null if disableSession is true or no session is created",
},
user: {
type: "object",
nullable: true,
properties: {
id: {
type: "string",
description: "Unique identifier of the user",
},
email: {
type: "string",
format: "email",
nullable: true,
description: "User's email address",
},
emailVerified: {
type: "boolean",
nullable: true,
description: "Whether the email is verified",
},
name: {
type: "string",
nullable: true,
description: "User's name",
},
image: {
type: "string",
format: "uri",
nullable: true,
description: "User's profile image URL",
},
phoneNumber: {
type: "string",
description: "User's phone number",
},
phoneNumberVerified: {
type: "boolean",
description:
"Whether the phone number is verified",
},
createdAt: {
type: "string",
format: "date-time",
description:
"Timestamp when the user was created",
},
updatedAt: {
type: "string",
format: "date-time",
description:
"Timestamp when the user was last updated",
},
},
required: [
"id",
"phoneNumber",
"phoneNumberVerified",
"createdAt",
"updatedAt",
],
description:
"User object with phone number details, null if no user is created or found",
},
},
required: ["status"],
},
},
},
},
400: {
description: "Invalid OTP",
},
},
},
},
},