login-with-phone
Method: POST
Path: /auth/login/phone
Tags: Auth
Summary
Login with phone
Description
Sends an OTP to the user's phone number. Returns an otp_token to pass to the verify-otp endpoint. Set register_if_not_exists to true to auto-register new users on OTP verification.
Storefront SDK Usage
SDK Method: sdk.auth.loginWithPhone()
Example:
typescript
// Login with phone number
const { data, error } = await sdk.auth.loginWithPhone({
phoneNumber: "9876543210",
countryCode: "+91",
registerIfNotExists: true
});
if (error) {
console.error("Login failed:", error.message);
} else {
console.log("OTP sent. Token:", data.otpToken);
console.log("Action:", data.action); // "login" or "register"
// Redirect user to OTP verification screen
}TypeScript Definition
typescript
"login-with-phone": {
parameters: {
query?: never;
header?: {
/** @description This param is used to enable debug mode. If debug mode is enabled, the API will return OTP as well. This is only for development and testing purposes. */
"x-debug-mode"?: components["parameters"]["DebugMode"];
};
path?: never;
cookie?: never;
};
requestBody: {
content: {
"application/json": {
/**
* @description Two-letter code begin with a plus sign prefix that identifies different countries. By default it will be +91 if not provided.
* @default +91
* @constant
*/
country_code?: "+91";
/** @description 10 digit phone number without country code. */
phone: string;
/** @description When `true`, auto-registers the user if the phone number is not found. Defaults to `false` (OTP sent only to registered users). */
register_if_not_exists?: boolean;
};
};
};
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
message: string;
success: boolean;
content: {
/** @description Token to pass to the verify-otp endpoint along with the OTP. */
otp_token: string;
/** @description Action type to pass to the verify-otp endpoint. */
otp_action: string;
};
};
};
};
400: components["responses"]["BadRequest"];
401: components["responses"]["Unauthorized"];
404: components["responses"]["NotFound"];
};
};Component References
| Reference | Resolves To |
|---|---|
components["parameters"]["DebugMode"] | DebugMode |
components["responses"]["BadRequest"] | BadRequest |
components["responses"]["Unauthorized"] | Unauthorized |
components["responses"]["NotFound"] | NotFound |
Parameters
- x-debug-mode (header): This param is used to enable debug mode. If debug mode is enabled, the API will return OTP as well. This is only for development and testing purposes.
Request Body
Content Types: application/json
Responses
200
OK
400
Bad request
401
Not authorized for given operation on the Resource
404
Requested resource not found
OpenAPI Definition
json
{
"tags": [
"Auth"
],
"operationId": "login-with-phone",
"summary": "Login with phone",
"description": "Sends an OTP to the user's phone number. Returns an `otp_token` to pass to the verify-otp endpoint. Set `register_if_not_exists` to `true` to auto-register new users on OTP verification.",
"externalDocs": {
"url": "https://llm-docs.commercengine.io/storefront/operations/login-with-phone",
"description": "API reference for the login-with-phone operation"
},
"parameters": [
{
"$ref": "#/components/parameters/DebugMode"
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"phone"
],
"properties": {
"country_code": {
"description": "Two-letter code begin with a plus sign prefix that identifies different countries. By default it will be +91 if not provided.",
"type": "string",
"default": "+91",
"const": "+91"
},
"phone": {
"description": "10 digit phone number without country code.",
"type": "string",
"maxLength": 10,
"minLength": 10,
"pattern": "^[0-9]{10}$"
},
"register_if_not_exists": {
"description": "When `true`, auto-registers the user if the phone number is not found. Defaults to `false` (OTP sent only to registered users).",
"type": "boolean"
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"message",
"success",
"content"
],
"properties": {
"message": {
"type": "string"
},
"success": {
"type": "boolean"
},
"content": {
"properties": {
"otp_token": {
"description": "Token to pass to the verify-otp endpoint along with the OTP.",
"type": "string"
},
"otp_action": {
"description": "Action type to pass to the verify-otp endpoint.",
"type": "string"
}
},
"required": [
"otp_token",
"otp_action"
],
"type": "object"
}
}
}
}
},
"links": {
"VerifyPhoneOtp": {
"operationId": "verify-otp",
"requestBody": {
"otp_action": "$response.body#/content/otp_action",
"otp_token": "$response.body#/content/otp_token"
},
"description": "Verify the OTP sent to the phone number."
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"404": {
"$ref": "#/components/responses/NotFound"
}
},
"security": [
{
"Authorization": []
}
],
"x-speakeasy-group": "auth",
"x-speakeasy-ignore": false,
"x-speakeasy-name-override": "loginWithPhone"
}Auto-generated from OpenAPI spec and TypeScript definitions