Skip to content

Commit

Permalink
Update auth-flow example to use transition hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Jun 9, 2014
1 parent d83cf7b commit 3ea85c2
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions examples/auth-flow/app.js
Expand Up @@ -45,14 +45,11 @@ var App = React.createClass({

var AuthenticatedRoute = {
statics: {
lastPath: null
},

componentWillMount: function() {
if (!auth.loggedIn()) {
this.render = function() { return <span/> };
AuthenticatedRoute.lastPath = Router.getCurrentPath();
Router.replaceWith('login');
willTransitionTo: function (transition) {
if (!auth.loggedIn()) {
Login.attemptedTransition = transition;
transition.redirect('/login');
}
}
}
};
Expand All @@ -73,6 +70,10 @@ var Dashboard = React.createClass({
});

var Login = React.createClass({
statics: {
attemptedTransition: null
},

getInitialState: function() {
return {
error: false
Expand All @@ -87,10 +88,13 @@ var Login = React.createClass({
if (!loggedIn)
return this.setState({ error: true });

if (AuthenticatedRoute.lastPath)
return Router.replaceWith(AuthenticatedRoute.lastPath);

Router.replaceWith('about');
if (Login.attemptedTransition) {
var transition = Login.attemptedTransition;
Login.attemptedTransition = null;
transition.retry();
} else {
Router.relaceWith('/about');
}
}.bind(this));
},

Expand Down

0 comments on commit 3ea85c2

Please sign in to comment.