From a1a4fd1bafc75cb53ba1a17281a509fef7683aba Mon Sep 17 00:00:00 2001 From: Saumya Pandey Date: Fri, 13 Aug 2021 12:32:18 +0530 Subject: [PATCH] fix: Redirect to collection on self-hosted (#2438) --- server/auth/index.js | 1 + server/utils/authentication.js | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/server/auth/index.js b/server/auth/index.js index 11254b5fd..df8e2bf38 100644 --- a/server/auth/index.js +++ b/server/auth/index.js @@ -45,6 +45,7 @@ router.get("/redirect", auth(), async (ctx) => { Team.findByPk(user.teamId), Collection.findOne({ where: { teamId: user.teamId }, + order: [["index", "ASC"]], }), View.findOne({ where: { userId: user.id }, diff --git a/server/utils/authentication.js b/server/utils/authentication.js index 7c9bf7032..66b1b85d3 100644 --- a/server/utils/authentication.js +++ b/server/utils/authentication.js @@ -4,7 +4,7 @@ import * as Sentry from "@sentry/node"; import { addMonths } from "date-fns"; import { type Context } from "koa"; import { pick } from "lodash"; -import { User, Event, Team } from "../models"; +import { User, Event, Team, Collection, View } from "../models"; import { getCookieDomain } from "../utils/domains"; export function getAllowedDomains(): string[] { @@ -99,6 +99,22 @@ export async function signIn( httpOnly: false, expires, }); - ctx.redirect(`${team.url}/home${isNewUser ? "?welcome" : ""}`); + + const [collection, view] = await Promise.all([ + Collection.findOne({ + where: { teamId: user.teamId }, + order: [["index", "ASC"]], + }), + View.findOne({ + where: { userId: user.id }, + }), + ]); + + const hasViewedDocuments = !!view; + ctx.redirect( + !hasViewedDocuments && collection + ? `${team.url}${collection.url}` + : `${team.url}/home` + ); } }