Skip to content

A login service based on mobile phone number for Meteor 3.0

License

Notifications You must be signed in to change notification settings

welkinwong/accounts-phone-password

Repository files navigation

accounts-phone-password

Accounts-Phone-Password is a Meteor package that let you authenticate by phone number. The package use SMS code verification to verify the user account. The package is based and inspired by okland:accounts-phone and Meteor Accounts-Password package.

this package only support Meteor 3.0

Install

In a Meteor app directory, enter:

$ meteor add welkinwong:accounts-phone-password

SMS Integration

you need set a SMS provider on server:

Accounts.sendSms = (phone: string, code: string) => {
  // SMS provider
};

Note: it can only be done on server

examples by aliyun SMS

import Dysmsapi20170525, { SendSmsRequest } from '@alicloud/dysmsapi20170525';
import * as OpenApi from '@alicloud/openapi-client';
import * as Util from '@alicloud/tea-util';

const config = new OpenApi.Config(/** Config **/);
config.endpoint = `dysmsapi.aliyuncs.com`;

const aliClient = new Dysmsapi20170525(config);

const templateCode = '/** templateCode **/';

Accounts.sendSms = (phone: string, code: string) => {
  aliClient
    .sendSmsWithOptions(
      new SendSmsRequest({
        phoneNumbers: phone,
        signName: '/** signName **/',
        templateCode,
        templateParam: `{code:${code}}`,
      }),
      new Util.RuntimeOptions({})
    )
    .catch(error => console.warn(error));
};

Usage

import { Accounts } from 'meteor/accounts-base';

requestPhoneVerification

Request a new verification code. create user if not exist

Accounts.requestPhoneVerification(phone: string, callback: (error: Meteor.Error) => void)

verifyPhone

Marks the user's phone as verified. Optional change passwords, Logs the user in afterwards

Accounts.verifyPhone(phone: string, code: string, newPassword?: string, callback?: (error: Meteor.Error) => void)

isPhoneVerified

Returns whether the current user phone is verified

Accounts.isPhoneVerified(): boolean

changePassword

Change the current user's password. Must be logged in.

Accounts.changePassword(oldPassword: string, newPassword: string, callback: (error: Meteor.Error) => void)

loginWithPhoneAndPassword

Log the user in with a password.

Meteor.loginWithPhoneAndPassword(selector: string | { phone: string } | { id: string }, password: string, callback: (error: Meteor.Error) => void)

Development

Setup

  1. Clone the repository
git clone https://github.com/welkinwong/accounts-phone-password.git
cd accounts-phone-password
  1. Install Dependencies
npm install && meteor

Testing

This repo contains tests to help reduce bugs and breakage. Before committing and submitting your changes, you should run the tests and make sure they pass. Follow these steps to run the tests for this repo.

  1. From the project directory, move into the testApp directory
link accounts-phone-password to project/packages
  1. Add local package
meteor add welkinwong:accounts-phone-password
  1. Run Tests
meteor test-packages

About

A login service based on mobile phone number for Meteor 3.0

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published