Coder Social home page Coder Social logo

meteor-accounts-login-state's Introduction

brettle:accounts-login-state

Build Status

Track the current user's login state and register callbacks that help calculate it.

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.

Installation

meteor add brettle:accounts-login-state

Usage

This package provides the following functions for tracking the current user's login state:

LoginState.loggedIn() - same as !! Meteor.userId() but reactive on the client so that switching between users won't rerun computations that depend on it.

LoginState.signedUp() - whether the current user has signed up via some sort of authenticated account, as opposed to an anonymous or guest user. This is reactive on the client. Accounts user interface packages should use the result of calling this function when determining whether to give the user the ability to sign-in/sign-up. The value returned by this function is false if LoginState.loggedIn() returns false. Otherwise, it's the value of Meteor.user().loginStateSignedUp. The server publishes the value of the loginStateSignedUp field and allows all callbacks registered with LoginState.addSignedUpInterceptor() to change it whenever the user record or set of configured services changes. On the server, LoginState.signedUp() itself takes an optional user argument (defaults to Meteor.user()) which you can use to determine whether a particular user has signed up.

Packages and applications that provide anonymous users, guest users, or other users that haven't signed up should call LoginState.addSignedUpInterceptor(callback) on the server to provide a callback that helps determine whether a user has signed up. The callback receives a single argument, which is the user record under consideration. The callback should set the user's loginStateSignedUp property to true if the callback can determine that the user has signed up, and false if the callback can determine that the user hasn't signed up. If the callback can't determine whether the current user has signed up, it should not change the property. It must not change any part of the user record other than the loginStateSignedUp property, and future versions of this package might remove such changes.

By default, there are 2 interceptors. The first considers the user signed up if you have installed accounts-password and the user has a password and either a username or an email. The second considers the user signed up if they have logged in with any 3rd party service configured with service-configuration.

Here is an example of adding an interceptor. Let's say you create guest users by using accounts-password to create users with random passwords and you set profile.guest = true. You could add an interceptor to treat those users as not signed up by running the following code on the server:

LoginState.addSignedUpInterceptor(function (u) {
  if (u.services && u.services.password && u.profile && u.profile.guest) {
    u.loginStateSignedUp = false;
  }
});

meteor-accounts-login-state's People

Contributors

brettle avatar

Stargazers

Paul Ray avatar Nicolas Azari avatar

Watchers

 avatar Ken Haigh avatar James Cloos avatar

Forkers

meteorich

meteor-accounts-login-state's Issues

Login-state causes error when loaded with Fastrender

I20151207-14:43:51.391(1)? Exception from task: TypeError: Cannot call method 'map' of undefined
I20151207-14:43:51.391(1)? at PublishContext.changed (packages/meteorhacks_fast-render/lib/server/publish_context.js:54:1)
I20151207-14:43:51.392(1)? at updateLoginStateSignedUp (packages/brettle_accounts-login-state/accounts-login-state-server.js:131:1)
I20151207-14:43:51.392(1)? at packages/mongo/observe_multiplex.js:208:1
I20151207-14:43:51.392(1)? at [object Object]..extend.forEach (packages/id-map/id-map.js:48:1)
I20151207-14:43:51.392(1)? at [object Object].
.extend.sendAdds (packages/mongo/observe_multiplex.js:200:1)
I20151207-14:43:51.392(1)? at [object Object].kadira_Multiplexer_sendAdds as _sendAdds
I20151207-14:43:51.393(1)? at packages/mongo/observe_multiplex.js:51:1
I20151207-14:43:51.393(1)? at runWithEnvironment (packages/meteor/dynamics_nodejs.js:110:1)
I20151207-14:43:51.393(1)? at Object.task (packages/meteor/dynamics_nodejs.js:123:1)
I20151207-14:43:51.393(1)? at [object Object].
.extend._run (packages/meteor/fiber_helpers.js:147:1)

is it possible to address this issue?

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.