Invalid user ID
Find out the solution for non-string user IDs.
The following error occurs when identifying a user with a non-string identifier, which is common in applications that use numeric sequences.
The user ID must be a string.
By design, the SDK does not perform automatic conversion to alert you to potential problems and avoid unexpected results that can occur when converting numbers to strings, especially when dealing with large numbers.
For enhanced security, use strong, randomly generated identifiers such as UUID v4 instead of easily guessable identifiers such as email addresses, phone numbers, or sequential numbers.
As a workaround, you can convert the numeric identifier to a string before calling any method that identifies the user, such as identify. Ideally, this should be done on the server side to avoid potential representation inconsistencies between the server and client.
If server-side conversion is not feasible, you can alternatively perform the conversion on the client side as follows:
function convertId(id) {if (!Number.isSafeInteger(id)) {throw new Error(`The ID "${id}" cannot be safely converted to a string.`);}return id.toFixed(0);}croct.identify(convertId(randomUserId));