Skip to content

Commit

Permalink
Framework: Redirect to Login page if logged out
Browse files Browse the repository at this point in the history
When you hit a valid route as a logged-out user, we should send you to the login page with a redirect back to the page you were trying to access. This is how all wp-admin links in core WP works.

There have been fixes for individual pages (eg #24687 ) but this should be handled at the framework level. We have an email campaign using the Simple Payments Guided Tour #24627 and it freezes at a blank screen for a logged-out user.

What this change does is to do a redirect for a valid section with the `enableLoggedOut` property set to true to the login screen with a redirect. A future PR could probably remove all bespoke uses of `import { redirectLoggedOut } from 'controller'` as well since this should supersede it.
  • Loading branch information
mattwiebe committed Jun 14, 2018
1 parent a96b8ca commit 66488b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client/boot/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ const loggedOutMiddleware = currentUser => {

page( '*', ( context, next ) => {
if ( isValidSection( context.path ) ) {
// redirect to login page if we're not on it already
if ( ! startsWith( context.path, '/log-in' ) ) {
return page.redirect( '/log-in/?redirect_to=' + encodeURIComponent( context.path ) );
}
next();
}
} );
Expand Down
1 change: 1 addition & 0 deletions client/wordpress-com.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ const sections = [
module: 'my-sites/stats',
secondary: true,
group: 'sites',
enableLoggedOut: true,
},
{
name: 'checklist',
Expand Down

0 comments on commit 66488b2

Please sign in to comment.