<@U04UQ68083H> I'm trying to build a registration ...
# ory-copilot
s
@chilly-king-10285 I'm trying to build a registration flow for phone with otp, i'm getting an error saying "Expected sms template but got <nil>"
b
A message from kapa.ai
Based on the information provided in the knowledge sources, it appears that you're encountering an issue with the SMS template for phone registration using OTP (One-Time Password) in Ory Kratos. To resolve this error, you need to ensure that you have properly configured the SMS channel and templates. Here are the steps you should follow: 1. Configure the SMS channel: Make sure you have set up an SMS channel in your Ory configuration. You can do this using the Ory CLI or by editing the configuration file directly. Here's an example of how to set up a basic SMS channel [using the Ory CLI](https://www.ory.sh/docs/kratos/emails-sms/sending-sms):
Copy code
ory patch identity-config --project ${project_id} \
     --add '/courier/channels=[{"id":"sms","request_config":{"method":"PUT","body":"<base64://ZnVuY3Rpb24oY3R4KSB7DQpjdHg6IGN0eCwNCn0>=","url":"<https://your-sms-provider-url.com>"}]'
Replace
<https://your-sms-provider-url.com>
with the actual URL of your SMS provider. 2. Configure the SMS template: You need to add the SMS template for the registration code. Add the following to your Ory configuration [using the Ory CLI](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#creating-templates):
Copy code
ory patch identity-config --project ${project_id} \
     --add '/courier/templates/registration_code/valid/sms/body/plaintext="Your registration code is: {{ .RegistrationCode }}"'
3. Ensure your identity schema is correctly configured: Make sure your identity schema includes a phone number trait that is marked for verification via SMS. Here's an example of how your schema should look [according to the documentation](https://www.ory.sh/docs/kratos/self-service/flows/verify-email-account-activation#phone-number-verification):
Copy code
json
   {
     "properties": {
       "traits": {
         "type": "object",
         "properties": {
           "phone": {
             "type": "string",
             "title": "Phone number",
             "format": "tel",
             "<http://ory.sh/kratos|ory.sh/kratos>": {
               "verification": {
                 "via": "sms"
               }
             }
           }
         }
       }
     }
   }
4. Enable passwordless login with one-time code: Make sure you have enabled the one-time code strategy for passwordless login [as described in the documentation](https://www.ory.sh/docs/kratos/passwordless/one-time-code#enable-sms-one-time-code-otp):
Copy code
ory patch identity-config <your-project-id> \
   --add '/selfservice/methods/code/passwordless_enabled=true'
After making these changes, your SMS templates should be properly configured, and you should no longer encounter the "Expected sms template but got <nil>" error.
Based on the information provided in the knowledge sources, it appears that you're encountering an issue with the SMS template for phone registration using OTP (One-Time Password) in Ory Kratos. To resolve this error, you need to ensure that you have properly configured the SMS channel and templates. Here are the steps you should follow: 1. Configure the SMS channel: Make sure you have set up an SMS channel in your Ory configuration. You can do this using the Ory CLI or by editing the configuration file directly. Here's an example of how to set up a basic SMS channel [using the Ory CLI](https://www.ory.sh/docs/kratos/emails-sms/sending-sms):
Copy code
ory patch identity-config --project ${project_id} \      --add '/courier/channels=[{"id":"sms","request_config":{"method":"PUT","body":"<base64://ZnVuY3Rpb24oY3R4KSB7DQpjdHg6IGN0eCwNCn0>=","url":"<https://your-sms-provider-url.com>"}]'
Replace
<https://your-sms-provider-url.com>
with the actual URL of your SMS provider. 2. Configure the SMS template: You need to add the SMS template for the registration code. Add the following to your Ory configuration [using the Ory CLI](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#creating-templates):
Copy code
ory patch identity-config --project ${project_id} \      --add '/courier/templates/registration_code/valid/sms/body/plaintext="Your registration code is: {{ .RegistrationCode }}"'
3. Ensure your identity schema is correctly configured: Make sure your identity schema includes a phone number trait that is marked for verification via SMS. Here's an example of how your schema should look [according to the documentation](https://www.ory.sh/docs/kratos/self-service/flows/verify-email-account-activation#phone-number-verification):
Copy code
json    {      "properties": {        "traits": {          "type": "object",          "properties": {            "phone": {              "type": "string",              "title": "Phone number",              "format": "tel",              "<http://ory.sh/kratos|ory.sh/kratos>": {                "verification": {                  "via": "sms"                }              }            }          }        }      }    }
4. Enable passwordless login with one-time code: Make sure you have enabled the one-time code strategy for passwordless login [as described in the documentation](https://www.ory.sh/docs/kratos/passwordless/one-time-code#enable-sms-one-time-code-otp):
Copy code
ory patch identity-config <your-project-id> \    --add '/selfservice/methods/code/passwordless_enabled=true'
After making these changes, your SMS templates should be properly configured, and you should no longer encounter the "Expected sms template but got <nil>" error. Remember that SMS-based authentication is considered less secure than other methods, as mentioned in the [overview of login and authentication methods](https://www.ory.sh/overview-login-password-passkey-webauthn-totp-sso-faceid/#login-code-via-sms). Consider using more secure authentication methods if possible. If you continue to experience issues after making these changes, you may need to review your entire Ory configuration or consult the Ory community for further assistance.