FIX: Redirect to default homepage when visiting `/login`

FIX: Redirect to default homepage when visiting `/login`

Previously this was hard-coded to redirect to /latest

From 071bd15463fd0f9d695624d0cc82ccffa9efacf6 Mon Sep 17 00:00:00 2001
From: David Taylor <david@taylorhq.com>
Date: Mon, 10 Dec 2018 15:39:05 +0000
Subject: [PATCH] FIX: Redirect to default homepage when visiting `/login`

Previously this was hard-coded to redirect to `/latest`

diff --git a/app/assets/javascripts/discourse/routes/login.js.es6 b/app/assets/javascripts/discourse/routes/login.js.es6
index 591b93a..8465ceb 100644
--- a/app/assets/javascripts/discourse/routes/login.js.es6
+++ b/app/assets/javascripts/discourse/routes/login.js.es6
@@ -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"));
       });
     }
diff --git a/test/javascripts/acceptance/login-redirect-test.js.es6 b/test/javascripts/acceptance/login-redirect-test.js.es6
new file mode 100644
index 0000000..1d8a86f
--- /dev/null
+++ b/test/javascripts/acceptance/login-redirect-test.js.es6
@@ -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"
+  );
+});

GitHub

2 Likes

This commit has been mentioned on Discourse Meta. There might be relevant details there: