Characteristic

CabloyJS has built-in SMS Verification module a-authsms. It mainly has the following characteristics:

  1. A general mechanism of SMS Verification, fast connection with various SMS service providers
  2. Realize the functions of user registration, user signin and user verification, etc.
  3. Built-in SMS service providers:
    • test: Development and debugging can be carried out without opening the actual SMS service
    • aliyun: Just fill in the parameters to quickly connect and deploy aliyun SMS service
    • Continue to increase support for third-party services

Screenshots

1. Sign Up

1

2. Sign In

2

3. Kitchen-sink - SMS Verification

3

4. Kitchen-sink - Test SMS service provider

4

How to use

1. Configure

By default, the SMS verification provided by the module will be enabled automatically. You can adjust the order or disable it through the following ways:

1.1 Adjust the order

For example, we now have two user authentication methods: a-authsimple/a-authsms. The display effect is as follows:

5

If we want a-authsms to display first, we only need to modify the configuration file:

src/backend/config/config.local.js

  // module config
  config.modules = {
    ...
    'a-login': {
      providers: [
        {
          module: 'a-authsms',
          provider: 'authsms',
        },
        {
          module: 'a-authsimple',
          provider: 'authsimple',
        },
      ],
    },
    ...
  };

1.2 Disable

If we want to disable a-authsimple, just set disable: true, as follows:

  // module config
  config.modules = {
    ...
    'a-login': {
      providers: [
        {
          module: 'a-authsms',
          provider: 'authsms',
        },
        {
          disable: true,
          module: 'a-authsimple',
          provider: 'authsimple',
        },
      ],
    },
    ...
  };

The final display effect is as follows:

6

2. Configure SMS service provider

2.1 test

By default, the built-in test SMS service provider is used. When the user enters the phone number and clicks the send code button, a random code will be automatically printed on the console to facilitate development and debugging. The effect is as follows:

7

2.2 aliyun

The module also has a built-in aliyun SMS service provider, which can be activated only by modifying the configuration file:

  // module config
  config.modules = {
    ...
    'a-authsms': {
      sms: {
        provider: {
          // default: '',
          default: 'aliyun',
        },
        providers: {
          aliyun: {
            accessKeyId: 'LTAIVnmixsvYC4cdF',
            secretAccessKey: 'V5F7Ke7w8QgZVpcvbYcHq32FKwt2ew',
            endpoint: 'https://dysmsapi.aliyuncs.com',
            apiVersion: '2017-05-25',
            signName: 'CabloyStore',
            templates: {
              mobileVerify: 'SMS_152015055',
              signup: 'SMS_152015055',
              signin: 'SMS_152015055',
            },
          },
        },
      },
    },
  };
  ...

signName and templates are parameters related to aliyun SMS service provider. Please refer to aliyun’s prompts for specific data

mobileVerify, signup and signin are the predefined scenes. You can specify separate message templates for different scenarios