Coder Social home page Coder Social logo

meteor-accounts-patch-ui's Introduction

brettle:accounts-patch-ui

Build Status

Monkey patches accounts UI packages to:

  • treat users that have logged in but not signed up (e.g. guests or anonymous users) like logged out users so that they can sign up and sign in.

  • suppress the error message that some packages display when adding a password service to an existing user.

This package is part of the brettle:accounts-* suite of packages. See brettle:accounts-deluxe for an overview of the suite and a live demo.

Features

  • Designed to support accounts-ui and useraccounts:* packages.

  • Provides utility functions to help monkey patch other packages

Installation

meteor add brettle:accounts-patch-ui

Basic Usage

For accounts-ui, ian:accounts-ui-bootstrap-3, and useraccounts:bootstrap with either useraccounts:iron-routing or useraccounts:flow-routing, it has been tested and should just work once installed. It has been designed to work with other accounts-ui-unstyled derivatives and useraccounts:* packages, but it has not been tested. Please report bugs.

Patching Other Packages

To patch other packages, use AccountsPatchUi.wrapWithSignedUp(originalFunc) and AccountsPatchUi.wrapWithMergedErrorSuppressed(originalFunc).

To treat guest/anonymous users like logged out users, you'll need to figure out which of their functions use Meteor.userId() or Meteor.user() to detect signed out users, and then wrap those functions using AccountsPatchUi.wrapWithSignedUp(originalFunc). While originalFunc is running, Meteor.userId() and Meteor.user() will return null if the current user is not signed up according to LoginState.signedUp(). For example, if you wanted to override the global currentUser helper so that it returns null if the current us is not signed up, you'd do:

Template.registerHelper("currentUser", 
  AccountsPatchUi.wrapWithSignedUp(function () {
    return Meteor.user();
  })
);

To suppress the error that a client-side call to a login method (e.g. Meteor.loginWith*(), or Accounts.createUser()) returns when the brettle:accounts-add-service package adds a service to the current user, you'll need to figure out which of the UI packages' functions call a login method when adding a service to an existing user, and wrap those functions using AccountsPatchUi.wrapWithMergedErrorSuppressed(originalFunc). While originalFunc is running, calls to login methods that would return the aforementioned error, will instead succeed (though Accounts.onLoginFailure() handlers will still run).

Testing

Because this package patches multiple accounts UI packages, it isn't possible to test them all simultaneously. Instead, when running meteor test-packages ./, you need to set the UI environment variable to indicate which accounts UI system to test. The choices are:

  • accounts-ui for the accounts UI package included with Meteor core
  • iron-routing for useraccounts with useraccounts:iron-routing
  • flow-routing for useraccounts with useraccounts:flow-routing

If the UI environment variable is not set, the tests will fail with a message saying to set it.

To test against new versions blaze, useraccounts, kadira:flow-router, or iron:router, update the following lines in package.js:

// Set versions to test against below.
var blazeVersion = '2.1.8';
var useraccountsVersion = '1.14.2';
var ironRouterVersion = '1.0.13';
var kadiraFlowRouterVersion = '2.12.1';

You will probably also need to add those versions to the list of compatible versions in the following lines, again in package.js:

// Use specific versions of the following packages because we rely on or
// monkey patch their internals. Those internals could change even in a patch
// release. So as new releases of these packages are published, we need to
// re-test this package with the new release, and add the supported version
// below.

// We monkey patch the _helpers and _eventMaps Template properties blaze
// manages.
api.use('blaze@=2.1.5 || =2.1.4 || =2.1.3 || =2.1.2 || =2.1.1 || =2.1.0' +
  ' || =2.1.6 || =2.1.7 || =2.1.8',
  'client');
// Among other things, we assume that the hooks in the options object are used
// directly, not copied.
api.use('iron:router@=1.0.13 || 1.0.12 || =1.0.11 || =1.0.10 || =1.0.9', 
  'client', { weak: true });
// Among other things, we use the internal _routesMap and _action properties.
// Also need the stop() function passed to triggers which was added in 2.5.0.
api.use('kadira:flow-router' +
  '@=2.12.1 || =2.10.1 || =2.9.0 || =2.8.0 || =2.7.0 || =2.6.2 || =2.5.0', 
  'client', { weak: true });

// We don't rely on the internals of these packages, but we do rely on
// Router.routes and FlowRouter.routes which are undocumented, so we
// should watch them closely.
api.use('useraccounts:[email protected]', 'client', { weak: true });
api.use('useraccounts:[email protected]', 'client', { weak: true });

To support testing on Travis-CI, ./run-tests-in-console.sh runs the tests with each of the different UI values. Note that console-based testing requires PhantomJS 2.

TODO

  • Test support for other useraccounts flavors.

meteor-accounts-patch-ui's People

Contributors

blackslate avatar brettle avatar

Watchers

 avatar  avatar  avatar

meteor-accounts-patch-ui's Issues

error: Conflict: Constraint

error: Conflict: Constraint blaze@=2.1.5 || =2.1.4 || =2.1.3 || =2.1.2 || =2.1.1 || =2.1.0 is not satisfied by blaze 2.1.5-rc.13

I solved this problem by updating the line

api.use('blaze@=2.1.3 || =2.1.2 || =2.1.1 || =2.1.0', 'client');

to

api.use('[email protected]', 'client');

I will open a corresponding PR, thanks

meteor 1.6.1

Blaze 2.1.8 support

:/

I feel lame creating an issue for this; what do you normally check for for compatibility in case I wanted to make a PR?

Error in error checking

Line 77 of accounts-patch-ui.js contains an error:

76   options.userCallback = function (error) {
77       if (error.error === Accounts.LoginCancelledError.numericError &&
78           error.reason === mergeUserErrorReason) {
79         return origCallback.call(this);
80       } else {
81         return origCallback.apply(this, arguments);
82      }

It should be:
if (error && error.error === Accounts.LoginCancelledError.numericError &&

Maximum call stack size exceeded

For some reason your package does not seem to work fine with matb33:collection-hooks. Here is the error it is throwing on startup.

Exception in template helper: RangeError: Maximum call stack size exceeded
    at Tracker.Dependency.depend (http://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:415:48)
    at _.extend.userId (http://localhost:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:4143:24)
    at AccountsClient.userId (http://localhost:3000/packages/accounts-base.js?37ee275552e2b0b0f518492f393eb55f395001ce:443:30)
    at Object.Meteor.userId (http://localhost:3000/packages/accounts-base.js?37ee275552e2b0b0f518492f393eb55f395001ce:298:19)
    at Object.signedUpUserIdFunc (http://localhost:3000/packages/brettle_accounts-patch-ui.js?e1612f9934003fba77a820dc4caafe77a2a67c91:48:39)
    at http://localhost:3000/packages/matb33_collection-hooks.js?57812df73cfb573558060484c53c71840fc10dcc:63:40
    at Object.Tracker.nonreactive (http://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:615:12)
    at Object.getUserId (http://localhost:3000/packages/matb33_collection-hooks.js?57812df73cfb573558060484c53c71840fc10dcc:62:13)
    at CollectionHooks.extendCollectionInstance._.each.collection.(anonymous function) [as findOne] (http://localhost:3000/packages/matb33_collection-hooks.js?57812df73cfb573558060484c53c71840fc10dcc:151:25)
    at Object.signedUpUserIdFunc (http://localhost:3000/packages/brettle_accounts-patch-ui.js?e1612f9934003fba77a820dc4caafe77a2a67c91:52:27)

Sign-in direct URL access does not work after logout (useraccounts)

Copied from brettle/meteor-accounts-deluxe#3:

Hi,
I have a problem with my app and I found out that it behaves same in your example http://brettle-accounts-demo.meteor.com/

To reproduce an error:

  1. I enter URL http://brettle-accounts-demo.meteor.com/sign-in
  2. I switch to useraccounts
  3. I press 'Sign In' button I Sign In with Google
  4. I press 'Sign Out' button
  5. I directly enter URL http://brettle-accounts-demo.meteor.com/sign-in and I am redirected to root '/' instead of Sign-in page

I got no redirect error with useraccounts package without brettle:accounts-deluxe package

I have same error when I install just brettle:accounts-anonymous-auto and brettle:accounts-patch-ui

meteor-useraccounts add service button text

Hi, thank you for your package.

I have one improvement. I don't exactly how to put it in if condition into your code and create a pull request. I just describe it.

When you use meteor-useraccounts and set option showAddRemoveServices to true. Then you can add services (facebook, google) when you logged in. Then in the form (as a logged in user) buttons have text 'add facebook'.

But when I am logged in anonymously social buttons should have text 'login with Facebook', but (because I am an anonymously logged in) they have 'add service'

You should add this behavior into the file path-useraccounts.js

I just use it outside of your package on the client side. I used wrapWithSignedUp function

var origButtonText = AccountsTemplates.atSocialHelpers.buttonText;
AccountsTemplates.atSocialHelpers.buttonText = AccountsPatchUi.wrapWithSignedUp(origButtonText);

// set helpers again, helper button text is wrapped with wrapWtihSignedUp funcion
Template.atSocial.helpers(AccountsTemplates.atSocialHelpers);

Meteor 1.4.4.2: Maximum call stack exceeded

Hi!

Thanks for the wonderful package.

Unfortunately, it seems like there was a breaking change when upgrading to Meteor 1.4.4.2,

I imagine it has something to do with this.

Here is the message I see:

Exception in template helper: RangeError: Maximum call stack size exceeded
    at Object.Tracker.nonreactive (http://localhost:3000/packages/tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:636:32)
    at Object.getUserId (http://localhost:3000/packages/matb33_collection-hooks.js?hash=b7fc18c7d776e58d66a188512f4674b43f774712:67:13)
    at Mongo.Collection.collection.(anonymous function) [as findOne] (http://localhost:3000/packages/matb33_collection-hooks.js?hash=b7fc18c7d776e58d66a188512f4674b43f774712:156:25)
    at Object.signedUpUserIdFunc (http://localhost:3000/packages/brettle_accounts-patch-ui.js?hash=f28c2b5718e28fdd21c8227f1c1fcf35bc878d0e:53:27)
    at http://localhost:3000/packages/matb33_collection-hooks.js?hash=b7fc18c7d776e58d66a188512f4674b43f774712:68:40
    at Object.Tracker.nonreactive (http://localhost:3000/packages/tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:640:12)
    at Object.getUserId (http://localhost:3000/packages/matb33_collection-hooks.js?hash=b7fc18c7d776e58d66a188512f4674b43f774712:67:13)
    at Mongo.Collection.collection.(anonymous function) [as findOne] (http://localhost:3000/packages/matb33_collection-hooks.js?hash=b7fc18c7d776e58d66a188512f4674b43f774712:156:25)
    at Object.signedUpUserIdFunc (http://localhost:3000/packages/brettle_accounts-patch-ui.js?hash=f28c2b5718e28fdd21c8227f1c1fcf35bc878d0e:53:27)
    at http://localhost:3000/packages/matb33_collection-hooks.js?hash=b7fc18c7d776e58d66a188512f4674b43f774712:68:40

Thanks!
-Lee

compability with meteor 1.3.1

Hi,
[email protected] uses [email protected], I cannot use your newest package.
Thank you in advance

meteor add brettle:[email protected]
=> Errors while adding packages:

While selecting package versions:
error: Conflict: Constraint blaze@=2.1.5 || =2.1.4 || =2.1.3 || =2.1.2 || =2.1.1 || =2.1.0 is not satisfied by blaze
2.1.6.
Constraints on package "blaze":
* blaze@=2.1.6 <- top level
* [email protected] <- accounts-base 1.2.5 <- accounts-facebook 1.0.8
* [email protected] <- spacebars 1.0.10
* [email protected] <- ui 1.0.10 <- blaze-html-templates 1.0.3
* [email protected] <- templating 1.1.8 <- blaze-html-templates 1.0.3
* [email protected] <- iron:layout 1.0.12 <- iron:controller 1.0.12 <- iron:router 1.0.12 <- brettle:accounts-patch-ui 0.1.11
* [email protected] <- iron:layout 1.0.12 <- iron:router 1.0.12 <- brettle:accounts-patch-ui 0.1.11
* [email protected] <- iron:dynamic-template 1.0.12 <- iron:controller 1.0.12 <- iron:router 1.0.12 <-
brettle:accounts-patch-ui 0.1.11
* [email protected] <- useraccounts:core 1.13.1
* [email protected] <- blaze-html-templates 1.0.3
* [email protected] <- launch-screen 1.0.10 <- mobile-experience 1.0.3
* blaze@=2.1.5 || =2.1.4 || =2.1.3 || =2.1.2 || =2.1.1 || =2.1.0 <- brettle:accounts-patch-ui 0.1.11
* [email protected] <- martino:iron-router-i18n 1.2.3
* [email protected] <- martino:i18n-conf 0.3.4 <- martino:iron-router-i18n 1.2.3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.