Skip to content

Commit

Permalink
fix: prevent other routes only when enabled and user is logged out
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Jun 8, 2022
1 parent 4440a39 commit fd60733
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
->default('sycho-private-facade.primary_color_bg', true)
->default('sycho-private-facade.force_redirect', true)
->default('sycho-private-facade.use_welcome_hero_text', true)
->serializeToForum('sycho-private-facade.force_redirect', 'sycho-private-facade.force_redirect', 'boolval')
->serializeToForum('sycho-private-facade.route_exclusions', 'sycho-private-facade.route_exclusions', function ($value) {
return PrivateFacadeMiddleware::getFrontendRouteExclusions($value);
})
Expand Down
4 changes: 3 additions & 1 deletion js/src/forum/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ app.initializers.add('sycho/flarum-private-facade', () => {
});

override(DefaultResolver.prototype, 'onmatch', function (orig, args, requestedPath, route) {
if (!app.forum.attribute<string[]>('sycho-private-facade.route_exclusions').includes(this.routeName)) {
if (!app.session.user
&& app.forum.attribute<boolean>('sycho-private-facade.force_redirect')
&& !app.forum.attribute<Array<string>>('sycho-private-facade.route_exclusions').includes(this.routeName)) {
return m.route.SKIP;
}

Expand Down

0 comments on commit fd60733

Please sign in to comment.