Blame view
imports/startup/client/routes.js
4.05 KB
c42d4eeac
|
1 |
/* eslint-disable max-len */ |
6be49625f
|
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import React from 'react'; import { render } from 'react-dom'; import { Router, Route, IndexRoute, browserHistory } from 'react-router'; import { Meteor } from 'meteor/meteor'; import App from '../../ui/layouts/App.js'; import Documents from '../../ui/pages/Documents.js'; import NewDocument from '../../ui/pages/NewDocument.js'; import EditDocument from '../../ui/containers/EditDocument.js'; import ViewDocument from '../../ui/containers/ViewDocument.js'; import Index from '../../ui/pages/Index.js'; import Login from '../../ui/pages/Login.js'; import NotFound from '../../ui/pages/NotFound.js'; import RecoverPassword from '../../ui/pages/RecoverPassword.js'; import ResetPassword from '../../ui/pages/ResetPassword.js'; import Signup from '../../ui/pages/Signup.js'; import { Orgs } from '/imports/collections/orgs/index'; |
2b1ad7917
|
18 |
|
4c9b3dfc1
|
19 |
const authenticate = (nextState, replace) => { |
cac7cbc73
|
20 |
if (!Meteor.loggingIn() && !Meteor.userId()) { |
2b1ad7917
|
21 22 |
replace({ pathname: '/login', |
cac7cbc73
|
23 |
state: { nextPathname: nextState.location.pathname }, |
2b1ad7917
|
24 25 26 |
}); } }; |
6be49625f
|
27 28 |
const detectOrg = (nextState, replace) => { orgSlug = ""; |
ff976df49
|
29 30 31 |
var hostnameArray = document.location.hostname.split( "." ); if(hostnameArray[1]=='localhost'){ orgSlug = hostnameArray[0]; |
6be49625f
|
32 33 34 35 36 37 38 39 40 41 42 43 |
} if(orgSlug!=""){ Meteor.call('checkExistingOrg', {slug:orgSlug}, function(err, res) { if(res.length>0){ console.log(res); console.log(res[0]._id._str); Session.set('orgId', res[0]._id._str); render(getOrgRoutes(),document.getElementById('react-root')); }else{ render(getInvalidOrgRoute(),document.getElementById('react-root')); } }); |
ff976df49
|
44 |
}else{ |
6be49625f
|
45 |
render(getNonOrgRoutes(),document.getElementById('react-root')); |
ff976df49
|
46 |
} |
ff976df49
|
47 |
} |
6be49625f
|
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
const checkSlug = (nextState, replace) => { orgId = Session.get('orgId'); console.log("orgId"); console.log(orgId); } const getOrgRoutes = () => ( <Router history={ browserHistory }> <Route path="/" component={ App }> <IndexRoute name="index" component={ Index } onEnter={ checkSlug } /> <Route name="login" path="/login" component={ Login } /> <Route name="recover-password" path="/recover-password" component={ RecoverPassword } /> <Route name="reset-password" path="/reset-password/:token" component={ ResetPassword } /> <Route path="*" component={ NotFound } /> </Route> </Router> ) const getNonOrgRoutes = () => ( <Router history={ browserHistory }> <Route path="/" component={ App }> <IndexRoute name="index" component={ Index } onEnter={ checkSlug } /> <Route name="signup" path="/signup" component={ Signup } /> <Route path="*" component={ NotFound } /> </Route> </Router> ) |
ff976df49
|
73 |
|
6be49625f
|
74 75 76 77 78 79 80 81 |
const getInvalidOrgRoute = () => ( <Router history={ browserHistory }> <Route path="/" component={ App }> <IndexRoute name="index" component={ NotFound } /> <Route path="*" component={ NotFound } /> </Route> </Router> ) |
2b1ad7917
|
82 |
|
27ed00b55
|
83 |
|
6be49625f
|
84 85 |
Meteor.startup(() => { detectOrg(); |
2b1ad7917
|
86 |
}); |