Hey, I have a problem wih usiing the passwordless ...
# support-questions-legacy
l
Hey, I have a problem wih usiing the passwordless recipe. I am using the python SDK with fastapi in my backend, custom ui (supertokens-web-js) on the frontend and a selfhosted core. All are updated to the latest version. (0.18.7 / 0.9.1 / 7.0). Here be backend config for the passwordless recipe:
Copy code
python
passwordless.init(passwordless.ContactConfig(
        contact_method='EMAIL'),
        flow_type='USER_INPUT_CODE_AND_MAGIC_LINK',
    )
And this is the rontend config:
Copy code
ts
import SuperTokens from 'supertokens-web-js';
import Session from 'supertokens-web-js/recipe/session';
import Passwordless from 'supertokens-web-js/recipe/passwordless'

const initSupertokens = () => {
    SuperTokens.init({
        appInfo: {
            apiDomain: process.env.NEXT_PUBLIC_BACKEND_HOST!,
            apiBasePath: "/auth",
            appName: "CM",
        },
        recipeList: [
            Session.init(),
            Passwordless.init({}),
        ],
    });
}

export default initSupertokens
after calling
Copy code
import { createCode } from "supertokens-web-js/recipe/passwordless";
...
const resp = await createCode({email})
i am getting
res.status = OK
Also my backend loggs:
Copy code
"POST /auth/signinup/code HTTP/1.1" 200 OK
and returns:
Copy code
json
{
    "status": "OK",
    "deviceId": "cY1ju3u88Tl7IDYc/JBf3duXTHoTbeAz5ujFr0ThODI=",
    "preAuthSessionId": "2S0TLFvqwGH9jX7KRM-IBnS4oP8nd8e-JkmsB0JnilY",
    "flowType": "USER_INPUT_CODE_AND_MAGIC_LINK"
}
But i am not getting any email. I tested several email addresses.
I also tried to override the email sending like this:
Copy code
python
def email_delivery(original_implementation: EmailDeliveryOverrideInput) -> EmailDeliveryOverrideInput:
    async def send_email(template_vars: EmailTemplateVars, user_context: Dict[str, Any]) -> None:
        email = template_vars.email
        magic_link = template_vars.url_with_link_code  # magic link
        otp = template_vars.user_input_code  # OTP
        valid_to_ms = template_vars.code_life_time

        valid_to = (datetime.now() + timedelta(milliseconds=valid_to_ms)).strftime('%H:%M')

        emails = EMailTemplateWorkflow(UUID_SYSTEM_USER)

        if template_vars.tenant_id == 'customers':
            emails.queue_customer_signinup_email(email, RenderCustomerSignInUpParams(
                otp=otp,
                magic_link=magic_link,
                valid_to=valid_to
            ))

    original_implementation.send_email = send_email
    return original_implementation

...

passwordless.init(passwordless.ContactConfig(
        contact_method='EMAIL'),
        flow_type='USER_INPUT_CODE_AND_MAGIC_LINK',
        email_delivery=EmailDeliveryConfig(
            override=email_delivery
        )
    )
If i do this, my custom function
send_email
is not called. Do you have any idea what's going wrong here?
r
Can you enable backend debug logs and show the output when you call the api?
l
@rp_st
Copy code
com.supertokens {"t": "2024-02-17T05:12:48.371Z", "sdkVer": "0.18.7", "message": "middleware: Started", "file": "supertokens.py:571"}

com.supertokens {"t": "2024-02-17T05:12:48.371Z", "sdkVer": "0.18.7", "message": "middleware: requestRID is: passwordless", "file": "supertokens.py:584"}

com.supertokens {"t": "2024-02-17T05:12:48.371Z", "sdkVer": "0.18.7", "message": "middleware: Checking recipe ID for match: session", "file": "supertokens.py:595"}

com.supertokens {"t": "2024-02-17T05:12:48.371Z", "sdkVer": "0.18.7", "message": "middleware: Checking recipe ID for match: thirdpartyemailpassword", "file": "supertokens.py:595"}

com.supertokens {"t": "2024-02-17T05:12:48.371Z", "sdkVer": "0.18.7", "message": "middleware: Checking recipe ID for match: emailverification", "file": "supertokens.py:595"}

com.supertokens {"t": "2024-02-17T05:12:48.371Z", "sdkVer": "0.18.7", "message": "middleware: Checking recipe ID for match: passwordless", "file": "supertokens.py:595"}

com.supertokens {"t": "2024-02-17T05:12:48.372Z", "sdkVer": "0.18.7", "message": "middleware: Matched with recipe ID: passwordless", "file": "supertokens.py:621"}

com.supertokens {"t": "2024-02-17T05:12:48.372Z", "sdkVer": "0.18.7", "message": "middleware: Request being handled by recipe. ID is: /signinup/code", "file": "supertokens.py:634"}

INFO:     45.152.161.90:0 - "POST /auth/signinup/code HTTP/1.1" 200 OK
com.supertokens {"t": "2024-02-17T05:12:48.467Z", "sdkVer": "0.18.7", "message": "Sending response to client with status code: 200", "file": "utils.py:155"}

com.supertokens {"t": "2024-02-17T05:12:48.468Z", "sdkVer": "0.18.7", "message": "middleware: Ended", "file": "supertokens.py:650"}
r
how have you added your override function to passwordless.init?
l
Copy code
python
passwordless.init(passwordless.ContactConfig(
        contact_method='EMAIL'),
        flow_type='USER_INPUT_CODE_AND_MAGIC_LINK',
        email_delivery=EmailDeliveryConfig(
            override=email_delivery
        )
    )
r
contact_config cannot be a string
see our docs once again in the backend setup
l
contact_config is not a string
its a asswordless.ContactConfig object
r
Copy code
from supertokens_python.recipe.passwordless import ContactEmailOnlyConfig
yeaa.. our sdk checks that it's an instance of
ContactEmailOnlyConfig
vs checking if the config.contact_method == 'EMAIL'
i guess it's sort of a bug in the sdk.. but in our docs, we don't say that you should do
passwordless.ContactConfig(contact_method='EMAIL')
(or do we?)
huh?
l
Using ContactEmailOnlyConfig works, thank you.
r
yup
l
wrong image 🙂
it guess the type hints here should be updated.
r
right. So COntactConfig is a super class of the individual configs.
ideally we should update the logic in our sdk to check for the string instance of checking for instance type
that way, either would work
l
👍
8 Views