You can do this by using our pre API hook feature of the frontend SDK to add custom attributes to the request body. You can then access the request object via the user context on the backend's createCode API to read this custom attribute and save it (in your db) against the preAuthSessionId created by the originalImplementation of createCode.
Finally, in the consumeCode API on the backend, you will have the same preAuthSessionId using which you can fetch the custom attribute and then you will know if the user who just signed up is a teacher or a student.