Verify Code
Verify a one-time password submitted by the user.
Verify a Code
verify.ts
import { YourSend } from 'yoursend';
const ys = new YourSend('ys_live_...');
const { data, error } = await ys.check({
message_id: 'msg_abc123', // from the send response
code: '123456', // user-provided code
});
if (data.valid) {
// Code is correct — grant access
} else {
// Invalid or expired code
}Response
Success response
{
"valid": true,
"message_id": "msg_abc123",
"channel": "sms",
"verified_at": "2026-03-18T12:00:00Z"
}Failed response
{
"valid": false,
"message_id": "msg_abc123",
"reason": "invalid_code" // or "expired", "already_verified"
}Error Handling
| Reason | Description |
|---|---|
| invalid_code | The code does not match |
| expired | The code has expired (default: 5 min) |
| already_verified | The code has already been used |
| not_found | No OTP found for this message_id |