Using supertokens (hosted), is there a direct way to query the userId of another user by email? The only solution I found was to fetch all users and search for it, which is obviously not efficient.
Depending on the recipe and the SDK you use, there are functions available for that. For example, with the NodeJS SDK, you have:
getUsersByEmail
(notice that this will return an array of users since you can have multiple users sign up with the same email, but different OAuth providers)
getUserByEmail
(This function will return Promise<undefined>
if the user doesn't exist, if if they had used phone number to sign up)
For other backend SDKs, you can check out their docs:
Python SDK -> choose your recipe -> choose either asyncio
or syncio
module (depending on your web framework execution env) and then you will see a list of functions exposed by that recipe. One of them will allow you to get the user from their email.
Golang SDK -> click on the "recipe" item, choose your recipe, and you will see a list of functions exposed by that recipe. One of them will allow you to get the user from their email.
In the API Spec, you can see sections for each recipe. Depending on how the user signed up, you can query that /recipe/user
GET API with their email as a query param. Be sure to pass in the correct rid
header in the GET request.