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
In a Meteor app directory, enter:
$ meteor add welkinwong:accounts-phone-password
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));
};
import { Accounts } from 'meteor/accounts-base';
Request a new verification code. create user if not exist
Accounts.requestPhoneVerification(phone: string, callback: (error: Meteor.Error) => void)
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)
Returns whether the current user phone is verified
Accounts.isPhoneVerified(): boolean
Change the current user's password. Must be logged in.
Accounts.changePassword(oldPassword: string, newPassword: string, callback: (error: Meteor.Error) => void)
Log the user in with a password.
Meteor.loginWithPhoneAndPassword(selector: string | { phone: string } | { id: string }, password: string, callback: (error: Meteor.Error) => void)
- Clone the repository
git clone https://github.com/welkinwong/accounts-phone-password.git
cd accounts-phone-password
- Install Dependencies
npm install && meteor
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