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:
1Accounts.sendSms = (phone: string, code: string) => { 2 // SMS provider 3};
Note: it can only be done on server
examples by aliyun SMS
1import Dysmsapi20170525, { SendSmsRequest } from '@alicloud/dysmsapi20170525'; 2import * as OpenApi from '@alicloud/openapi-client'; 3import * as Util from '@alicloud/tea-util'; 4 5const config = new OpenApi.Config(/** Config **/); 6config.endpoint = `dysmsapi.aliyuncs.com`; 7 8const aliClient = new Dysmsapi20170525(config); 9 10const templateCode = '/** templateCode **/'; 11 12Accounts.sendSms = (phone: string, code: string) => { 13 aliClient 14 .sendSmsWithOptions( 15 new SendSmsRequest({ 16 phoneNumbers: phone, 17 signName: '/** signName **/', 18 templateCode, 19 templateParam: `{code:${code}}`, 20 }), 21 new Util.RuntimeOptions({}) 22 ) 23 .catch(error => console.warn(error)); 24};
Usage
1import { Accounts } from 'meteor/accounts-base';
requestPhoneVerification
Request a new verification code. create user if not exist
1Accounts.requestPhoneVerification(phone: string, callback: (error: Meteor.Error) => void)
verifyPhone
Marks the user's phone as verified. Optional change passwords, Logs the user in afterwards
1Accounts.verifyPhone(phone: string, code: string, newPassword?: string, callback?: (error: Meteor.Error) => void)
isPhoneVerified
Returns whether the current user phone is verified
1Accounts.isPhoneVerified(): boolean
changePassword
Change the current user's password. Must be logged in.
1Accounts.changePassword(oldPassword: string, newPassword: string, callback: (error: Meteor.Error) => void)
loginWithPhoneAndPassword
Log the user in with a password.
1Meteor.loginWithPhoneAndPassword(selector: string | { phone: string } | { id: string }, password: string, callback: (error: Meteor.Error) => void)
Development
Setup
- Clone the repository
git clone https://github.com/welkinwong/accounts-phone-password.git
cd accounts-phone-password
- 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.
- From the project directory, move into the testApp directory
link accounts-phone-password to project/packages
- Add local package
meteor add welkinwong:accounts-phone-password
- Run Tests
meteor test-packages