fix: Redirect to collection on self-hosted (#2438)

This commit is contained in:
Saumya Pandey
2021-08-13 12:32:18 +05:30
committed by GitHub
parent 31f4424018
commit a1a4fd1baf
2 changed files with 19 additions and 2 deletions

View File

@ -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 },

View File

@ -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`
);
}
}