A token is not a string. If you encode a token directly into a string using new String(nextToken), information is lost and the token becomes invalid.
To persist a nextToken or transfer it to a frontend, encode the token into a Base64 string. This prevents information loss and ensures the token remains valid for storage and transfer.