Code Monkey home page Code Monkey logo

loginfirst's Introduction

Ensure that users log in first in a Meteor application.

This works by blocking client DDP messages (for method calls and subscriptions), until .setUserId() is called.

Instructions

If you would like to enforce that your application not work at all for not logged-in users, proceed as follows:

  1. meteor add epfl:loginfirst
  2. (optional) Whitelist any Meteor methods and subscriptions that should not be delayed, e.g.
    import LoginFirst from 'meteor/epfl:loginfirst'
    LoginFirst.whitelist.methods.append("myInnocuousMethodThatIsSoImportantThatItCannotWaitForTheUserToLogInFirst")
    LoginFirst.whitelist.subscriptions.append("dittoForSubscription")
    
  3. ???
  4. Profit!

(Step 3 may involve, you know, putting some work into your project)

How It Works

The server rejects any and all method calls and subscription requests (unless whitelisted), and rejects them promptly (i.e. no server-side DDP message reordering takes place), unless and until the user is logged in.

As far as subscriptions are concerned, the Meteor client-side runtime does subscribe to a handful of them automagically as soon as the app starts, and some of your app's widgets might do same. All of these subscriptions will get a nosub DDP response before login completes — But that is harmless, because client-side Meteor already knows to retry all subscriptions whenever the login method succeeds¹. Also, the meteor.loginServiceConfiguration subscription is whitelisted by default, which is enough to let your app display a multi-provider login widget (with server-side list of providers) if it was programmed to do so prior to enabling epfl:loginfirst.

If you need to call a DDP method before login (which should be fairly unusual), make sure to whitelist it (see above).

¹ Covered by a test in meteor/packages/accounts-base/accounts_reconnect_tests.js

Developer Instructions

Running the test suite

  1. Make sure that you git clone this package outside of any Meteor application.
    💡 If you insist on wanting a cloned epfl:loginfirst in your Meteor application's packages/ subdirectory, you can use a symlink
  2. Run
    env TEST_CLIENT=0 meteor test-packages ./ --driver-package meteortesting:mocha
    ... which should give you a nice and terse green bar; but in the, hopefully unusual case that it doesn't, use this instead to investigate:
    env DEBUG='loginfirst*' TEST_CLIENT=0 meteor test-packages ./ --driver-package meteortesting:mocha

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.