1
0
mirror of https://github.com/ascribe/onion.git synced 2025-02-14 21:10:27 +01:00

WIP signup/login redirect and redirectAuthenticated

This commit is contained in:
diminator 2015-09-30 15:08:45 +02:00
parent 2aef82be0b
commit 0d6e82a45d
2 changed files with 24 additions and 1 deletions

View File

@ -44,6 +44,10 @@ let LoginForm = React.createClass({
componentDidMount() { componentDidMount() {
UserStore.listen(this.onChange); UserStore.listen(this.onChange);
let { redirect } = this.getQuery();
if (redirect !== 'login'){
this.transitionTo(redirect, null, this.getQuery());
}
}, },
componentWillUnmount() { componentWillUnmount() {
@ -56,6 +60,15 @@ let LoginForm = React.createClass({
// if user is already logged in, redirect him to piece list // if user is already logged in, redirect him to piece list
if(this.state.currentUser && this.state.currentUser.email && this.props.redirectOnLoggedIn) { if(this.state.currentUser && this.state.currentUser.email && this.props.redirectOnLoggedIn) {
// FIXME: hack to redirect out of the dispatch cycle // FIXME: hack to redirect out of the dispatch cycle
let { redirectAuthenticated } = this.getQuery();
if ( redirectAuthenticated) {
/*
* redirectAuthenticated contains an arbirary path
* eg pieces/<id>, editions/<bitcoin_id>, collection, settings, ...
* hence transitionTo cannot be used directly
*/
window.location = AppConstants.baseUrl + redirectAuthenticated;
}
window.setTimeout(() => this.transitionTo('pieces'), 0); window.setTimeout(() => this.transitionTo('pieces'), 0);
} }
}, },
@ -79,7 +92,13 @@ let LoginForm = React.createClass({
Users on Stack Overflow claim this is a bug in chrome and should be fixed in the future. Users on Stack Overflow claim this is a bug in chrome and should be fixed in the future.
Until then, we redirect the HARD way, but reloading the whole page using window.location Until then, we redirect the HARD way, but reloading the whole page using window.location
*/ */
window.location = AppConstants.baseUrl + 'collection'; let { redirectAuthenticated } = this.getQuery();
if ( redirectAuthenticated) {
window.location = AppConstants.baseUrl + redirectAuthenticated;
}
else {
window.location = AppConstants.baseUrl + 'collection';
}
} else if(this.props.onLogin) { } else if(this.props.onLogin) {
// In some instances we want to give a callback to an outer container, // In some instances we want to give a callback to an outer container,
// to show that the one login action the user triggered actually went through. // to show that the one login action the user triggered actually went through.

View File

@ -40,6 +40,10 @@ let SignupForm = React.createClass({
componentDidMount() { componentDidMount() {
UserStore.listen(this.onChange); UserStore.listen(this.onChange);
let { redirect } = this.getQuery();
if (redirect !== 'signup'){
this.transitionTo(redirect, null, this.getQuery());
}
}, },
componentWillUnmount() { componentWillUnmount() {