Skip to content

Commit 29a64de

Browse files
author
EC2 Default User
committed
Add verbose mode
1 parent 59ad290 commit 29a64de

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

docs/api.md

+9
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,12 @@ Mirrors Meteor's observe behavior. Accepts object with the properties `added`, `
9494
* [Accounts.onLogin](http://docs.meteor.com/#/full/accounts_onlogin)
9595
* [Accounts.onLoginFailure](http://docs.meteor.com/#/full/accounts_onloginfailure)
9696
* `Accounts._hashPassword` - SHA-256 hashes password, for use with methods that may require authentication
97+
98+
## enableVerbose
99+
`import { enableVerbose } from '@meteorrn/core';`
100+
101+
Enables verbose mode which logs detailed information about accounts. **Note:** this will expose login tokens and other private information to the console.
102+
103+
````
104+
enableVerbose()
105+
````

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@meteorrn/core",
3-
"version": "2.0.8",
3+
"version": "2.0.9",
44
"description": "Full Meteor Client for React Native",
55
"main": "src/Meteor.js",
66
"repository": {

src/Meteor.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import NetInfo from "@react-native-community/netinfo";
22

33
import { name as packageName } from '../package.json';
44

5-
if(name !== "@meteorrn/core") {
5+
if(packageName !== "@meteorrn/core") {
66
console.error(`DEPRECATED: Please change "meteor-react-native" in your package.json to "@meteorrn/core" and run npm install`);
77
}
88

@@ -23,7 +23,12 @@ import ReactiveDict from './ReactiveDict';
2323
import User from './user/User';
2424
import Accounts from './user/Accounts';
2525

26+
export let isVerbose = false;
27+
2628
module.exports = {
29+
enableVerbose() {
30+
isVerbose = true;
31+
},
2732
Random,
2833
Accounts,
2934
Mongo,
@@ -116,7 +121,9 @@ module.exports = {
116121

117122
Data.notify('change');
118123

119-
console.info('Connected to DDP server.');
124+
if(isVerbose) {
125+
console.info('Connected to DDP server.');
126+
}
120127
this._loadInitialUser().then(() => {
121128
this._subscriptionsRestart();
122129
});

src/user/Accounts.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Data from '../Data';
22
import call from '../Call';
33
import User from './User';
44
import { hashPassword } from '../../lib/utils';
5+
import {isVerbose} from '../Meteor.js';
56

67
module.exports = {
78
_hashPassword:hashPassword,
@@ -14,10 +15,10 @@ module.exports = {
1415

1516
User._startLoggingIn();
1617
call('createUser', options, (err, result) => {
18+
isVerbose && console.info("Accounts.createUser::: err:", err, "result:", result);
19+
1720
User._endLoggingIn();
18-
1921
User._handleLoginCallback(err, result);
20-
2122
callback(err);
2223
});
2324
},
@@ -52,6 +53,8 @@ module.exports = {
5253
}
5354

5455
call('resetPassword', token, hashPassword(newPassword), (err, result) => {
56+
isVerbose && console.info("Accounts.resetPassword::: err:", err, "result:", result);
57+
5558
if (!err) {
5659
User._loginWithToken(result.token);
5760
}

src/user/User.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Data from '../Data';
22
import { hashPassword } from '../../lib/utils';
33
import call from '../Call';
44
import Mongo from '../Mongo';
5+
import {isVerbose} from '../Meteor.js';
56

67
const TOKEN_KEY = 'reactnativemeteor_usertoken';
78
const Users = new Mongo.Collection("users");
@@ -89,12 +90,13 @@ module.exports = {
8990
},
9091
_handleLoginCallback(err, result) {
9192
if (!err) {
92-
//save user id and token
93+
isVerbose && console.info("User._handleLoginCallback::: token:", result.token, "id:", result.id);
9394
Data._options.AsyncStorage.setItem(TOKEN_KEY, result.token);
9495
Data._tokenIdSaved = result.token;
9596
this._userIdSaved = result.id;
9697
Data.notify('onLogin');
9798
} else {
99+
isVerbose && console.info("User._handleLoginCallback::: error:", err);
98100
Data.notify('onLoginFailure');
99101
this.handleLogout();
100102
}

0 commit comments

Comments
 (0)