FIX: Redirect to default homepage when visiting /login

Previously this was hard-coded to redirect to `/latest`
This commit is contained in:
David Taylor 2018-12-10 15:39:05 +00:00
parent ef7f84b59b
commit 071bd15463
2 changed files with 22 additions and 1 deletions

View File

@ -1,11 +1,12 @@
import buildStaticRoute from "discourse/routes/build-static-route";
import { defaultHomepage } from "discourse/lib/utilities";
const LoginRoute = buildStaticRoute("login");
LoginRoute.reopen({
beforeModel() {
if (!this.siteSettings.login_required) {
this.replaceWith("discovery.latest").then(e => {
this.replaceWith(`/${defaultHomepage()}`).then(e => {
Ember.run.next(() => e.send("showLogin"));
});
}

View File

@ -0,0 +1,20 @@
import { acceptance } from "helpers/qunit-helpers";
acceptance("Login redirect", {});
QUnit.test("redirects categories to top", async assert => {
await visit("/login");
assert.equal(
currentPath(),
"discovery.latest",
"it works when latest is the homepage"
);
Discourse.SiteSettings.top_menu = "categories|latest|top|hot";
await visit("/login");
assert.equal(
currentPath(),
"discovery.categories",
"it works when categories is the homepage"
);
});