Manually generating a link
You can use our backend SDK to generate the reset password link as shown below:
- NodeJS
- GoLang
- Python
- Other Frameworks
Important
For other backend frameworks, you can follow our guide on how to spin up a separate server configured with the SuperTokens backend SDK to authenticate requests and issue session tokens.
import EmailPassword from "supertokens-node/recipe/emailpassword";
async function createResetPasswordLink(userId: string, email: string) {
const linkResponse = await EmailPassword.createResetPasswordLink("public", userId, email);
if (linkResponse.status === "OK") {
console.log(linkResponse.link);
} else {
// user does not exist or is not an email password user
}
}
import (
"fmt"
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
)
func main() {
userID := "..."
linkRes, err := emailpassword.CreateResetPasswordLink("public", userID)
if err != nil {
// handle error
}
if linkRes.OK != nil {
link := linkRes.OK.Link
fmt.Println(link)
} else {
// user does not exist or is not an email password user
}
}
- Asyncio
- Syncio
from supertokens_python.recipe.emailpassword.asyncio import create_reset_password_link
from supertokens_python.recipe.emailpassword.interfaces import CreateResetPasswordLinkOkResult
async def create_link(user_id: str):
link_res = await create_reset_password_link("public", user_id)
if isinstance(link_res, CreateResetPasswordLinkOkResult):
link = link_res.link
print(link)
else:
print("user does not exist or is not an email password user")
from supertokens_python.recipe.thirdpartyemailpassword.syncio import create_reset_password_link
from supertokens_python.recipe.thirdpartyemailpassword.interfaces import CreateResetPasswordLinkOkResult
def create_link(user_id: str):
link_res = create_reset_password_link("public", user_id)
if isinstance(link_res, CreateResetPasswordLinkOkResult):
link = link_res.link
print(link)
else:
print("user does not exist or is not an email password user")
Multi Tenancy
Notice that the first argument to the function call above is "public"
. This refers to the default tenant ID that is used in SuperTokens. It means that the generated password reset link can only be consumed by users belonging to the "public"
tenant.
If you are using our multi tenancy feature, you can pass in the tenantId that contains this user, which you can fetch by getting the user object for this userId.
Finally, the generated link will use the configured websiteDomain
from the appInfo
object (in supertokens.init
), however, you can change the domain of the generated link to match that of the tenant ID.