Skip to content

Commit 096fcb6

Browse files
committed
Merge pull request #861 from zenlambda/auth-flow-suggestion
Use query params instead of statics to communicate the next transition
2 parents cfff382 + de9f809 commit 096fcb6

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

examples/auth-flow/app.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var React = require('react');
22
var Router = require('react-router');
3-
var { Route, RouteHandler, Link } = Router;
3+
var { Route, RouteHandler, Link, State } = Router;
44

55
var App = React.createClass({
66
getInitialState: function () {
@@ -40,9 +40,10 @@ var App = React.createClass({
4040
var Authentication = {
4141
statics: {
4242
willTransitionTo: function (transition) {
43+
var nextPath = transition.path;
4344
if (!auth.loggedIn()) {
44-
Login.attemptedTransition = transition;
45-
transition.redirect('/login');
45+
transition.redirect('/login',{},
46+
{ 'nextPath' : nextPath });
4647
}
4748
}
4849
}
@@ -64,11 +65,7 @@ var Dashboard = React.createClass({
6465
});
6566

6667
var Login = React.createClass({
67-
mixins: [ Router.Navigation ],
68-
69-
statics: {
70-
attemptedTransition: null
71-
},
68+
mixins: [ Router.Navigation, State],
7269

7370
getInitialState: function () {
7471
return {
@@ -78,16 +75,15 @@ var Login = React.createClass({
7875

7976
handleSubmit: function (event) {
8077
event.preventDefault();
78+
var nextPath = this.getQuery().nextPath;
8179
var email = this.refs.email.getDOMNode().value;
8280
var pass = this.refs.pass.getDOMNode().value;
8381
auth.login(email, pass, function (loggedIn) {
8482
if (!loggedIn)
8583
return this.setState({ error: true });
8684

87-
if (Login.attemptedTransition) {
88-
var transition = Login.attemptedTransition;
89-
Login.attemptedTransition = null;
90-
transition.retry();
85+
if (nextPath) {
86+
this.transitionTo(nextPath);
9187
} else {
9288
this.replaceWith('/about');
9389
}

0 commit comments

Comments
 (0)