├── .versions ├── package.js ├── README.md └── meteor-react-guard.js /.versions: -------------------------------------------------------------------------------- 1 | babel-compiler@6.18.1 2 | babel-runtime@1.0.1 3 | ecmascript@0.7.2 4 | ecmascript-runtime@0.3.15 5 | meteor@1.6.1 6 | modules@0.8.1 7 | modules-runtime@0.7.10 8 | poetic:meteor-react-guard@2.3.0 9 | promise@0.8.8 10 | react-meteor-data@0.2.9 11 | tmeasday:check-npm-versions@0.2.0 12 | tracker@1.1.2 13 | underscore@1.0.10 14 | -------------------------------------------------------------------------------- /package.js: -------------------------------------------------------------------------------- 1 | Package.describe({ 2 | name: 'poetic:meteor-react-guard', 3 | version: '2.3.0', 4 | // Brief, one-line summary of the package. 5 | summary: 'Guard your react app against unlogged in users and on-going subscriptions', 6 | // URL to the Git repository containing the source code for this package. 7 | git: 'git@github.com:poetic/meteor-react-guard.git', 8 | // By default, Meteor will default to using README.md for documentation. 9 | // To avoid submitting documentation, set this field to null. 10 | documentation: 'README.md' 11 | }); 12 | 13 | Package.onUse(function(api) { 14 | api.versionsFrom('1.4.2'); 15 | api.use('ecmascript'); 16 | api.use('react-meteor-data@0.2.9') 17 | api.mainModule('meteor-react-guard.js', 'client'); 18 | }); 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Example 2 | 3 | ``` 4 | import { GuardUser, GuardSubscriptions } from 'meteor/poetic:meteor-react-guard'; 5 | 6 | Meteor.startup(() => { 7 | const getSubscriptions = () => ([ 8 | Meteor.subscribe('domains'), 9 | Meteor.subscribe('subDomains'), 10 | Meteor.subscribe('workflows'), 11 | ]); 12 | 13 | const guardedApp = ( 14 | Trying to log in} 16 | loginElement={

This is the login form

} 17 | > 18 | Subscriptions are not ready} 21 | > 22 |

Subscriptions are ready

23 |
24 |
25 | ) 26 | 27 | render(guardedApp, document.getElementById('render-target')); 28 | }); 29 | ``` 30 | -------------------------------------------------------------------------------- /meteor-react-guard.js: -------------------------------------------------------------------------------- 1 | import { Meteor } from 'meteor/meteor' 2 | import { createContainer } from 'meteor/react-meteor-data' 3 | 4 | export const GuardUser = createContainer( 5 | () => { 6 | if (Meteor.loggingIn()) { 7 | return { status: 'LOADING' } 8 | } 9 | return { status: Meteor.user() ? 'LOGGEDIN' : 'LOGGEDOUT' } 10 | }, 11 | ({ loadingElement, loginElement, status, bypass, children, getChildren }) => { 12 | if (bypass) { 13 | return children 14 | } 15 | 16 | if (status === 'LOADING') { 17 | return loadingElement 18 | } 19 | if (status === 'LOGGEDOUT') { 20 | return loginElement 21 | } 22 | if (getChildren) { 23 | return getChildren() 24 | } 25 | return children 26 | } 27 | ) 28 | 29 | export const GuardReady = createContainer( 30 | ({ getReady }) => ({ ready: getReady() }), 31 | ({ ready, children, getChildren, loadingElement }) => { 32 | if (ready) { 33 | if (getChildren) { 34 | return getChildren() 35 | } 36 | return children 37 | } 38 | return loadingElement 39 | } 40 | ) 41 | --------------------------------------------------------------------------------