fix: enable sessions for API keys (#283)
* fix: enable sessions for API keys * chore: remove old due date filters * chore: update lockfile * fix: temp ignore eslint errors on build
This commit is contained in:
@@ -8,17 +8,15 @@ import * as labelRepo from "@kan/db/repository/label.repo";
|
||||
import * as listRepo from "@kan/db/repository/list.repo";
|
||||
import * as workspaceRepo from "@kan/db/repository/workspace.repo";
|
||||
import { colours } from "@kan/shared/constants";
|
||||
import { generateSlug, generateUID } from "@kan/shared/utils";
|
||||
import {
|
||||
convertDueDateFiltersToRanges,
|
||||
generateSlug,
|
||||
generateUID,
|
||||
} from "@kan/shared/utils";
|
||||
|
||||
import { createTRPCRouter, protectedProcedure, publicProcedure } from "../trpc";
|
||||
import { assertUserInWorkspace } from "../utils/auth";
|
||||
|
||||
const dueDateFilterSchema = z.object({
|
||||
startDate: z.string().datetime().optional(),
|
||||
endDate: z.string().datetime().optional(),
|
||||
hasNoDueDate: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export const boardRouter = createTRPCRouter({
|
||||
all: protectedProcedure
|
||||
.meta({
|
||||
@@ -85,7 +83,18 @@ export const boardRouter = createTRPCRouter({
|
||||
members: z.array(z.string().min(12)).optional(),
|
||||
labels: z.array(z.string().min(12)).optional(),
|
||||
lists: z.array(z.string().min(12)).optional(),
|
||||
dueDate: z.array(dueDateFilterSchema).optional(),
|
||||
dueDateFilters: z
|
||||
.array(
|
||||
z.enum([
|
||||
"overdue",
|
||||
"today",
|
||||
"tomorrow",
|
||||
"next-week",
|
||||
"next-month",
|
||||
"no-due-date",
|
||||
]),
|
||||
)
|
||||
.optional(),
|
||||
type: z.enum(["regular", "template"]).optional(),
|
||||
}),
|
||||
)
|
||||
@@ -112,6 +121,11 @@ export const boardRouter = createTRPCRouter({
|
||||
|
||||
await assertUserInWorkspace(ctx.db, userId, board.workspaceId);
|
||||
|
||||
// Convert semantic string filters to date ranges expected by the repo
|
||||
const dueDateFilters = input.dueDateFilters
|
||||
? convertDueDateFiltersToRanges(input.dueDateFilters)
|
||||
: [];
|
||||
|
||||
const result = await boardRepo.getByPublicId(
|
||||
ctx.db,
|
||||
input.boardPublicId,
|
||||
@@ -119,14 +133,7 @@ export const boardRouter = createTRPCRouter({
|
||||
members: input.members ?? [],
|
||||
labels: input.labels ?? [],
|
||||
lists: input.lists ?? [],
|
||||
dueDate:
|
||||
input.dueDate?.map((filter) => ({
|
||||
startDate: filter.startDate
|
||||
? new Date(filter.startDate)
|
||||
: undefined,
|
||||
endDate: filter.endDate ? new Date(filter.endDate) : undefined,
|
||||
hasNoDueDate: filter.hasNoDueDate,
|
||||
})) ?? [],
|
||||
dueDate: dueDateFilters,
|
||||
type: input.type,
|
||||
},
|
||||
);
|
||||
@@ -160,7 +167,18 @@ export const boardRouter = createTRPCRouter({
|
||||
members: z.array(z.string().min(12)).optional(),
|
||||
labels: z.array(z.string().min(12)).optional(),
|
||||
lists: z.array(z.string().min(12)).optional(),
|
||||
dueDate: z.array(dueDateFilterSchema).optional(),
|
||||
dueDateFilters: z
|
||||
.array(
|
||||
z.enum([
|
||||
"overdue",
|
||||
"today",
|
||||
"tomorrow",
|
||||
"next-week",
|
||||
"next-month",
|
||||
"no-due-date",
|
||||
]),
|
||||
)
|
||||
.optional(),
|
||||
}),
|
||||
)
|
||||
.output(z.custom<Awaited<ReturnType<typeof boardRepo.getBySlug>>>())
|
||||
@@ -176,6 +194,11 @@ export const boardRouter = createTRPCRouter({
|
||||
code: "NOT_FOUND",
|
||||
});
|
||||
|
||||
// Convert semantic string filters to date ranges expected by the repo
|
||||
const dueDateFilters = input.dueDateFilters
|
||||
? convertDueDateFiltersToRanges(input.dueDateFilters)
|
||||
: [];
|
||||
|
||||
const result = await boardRepo.getBySlug(
|
||||
ctx.db,
|
||||
input.boardSlug,
|
||||
@@ -184,14 +207,7 @@ export const boardRouter = createTRPCRouter({
|
||||
members: input.members ?? [],
|
||||
labels: input.labels ?? [],
|
||||
lists: input.lists ?? [],
|
||||
dueDate:
|
||||
input.dueDate?.map((filter) => ({
|
||||
startDate: filter.startDate
|
||||
? new Date(filter.startDate)
|
||||
: undefined,
|
||||
endDate: filter.endDate ? new Date(filter.endDate) : undefined,
|
||||
hasNoDueDate: filter.hasNoDueDate,
|
||||
})) ?? [],
|
||||
dueDate: dueDateFilters,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -306,12 +322,6 @@ export const boardRouter = createTRPCRouter({
|
||||
sourceBoardId: sourceBoardInfo.id,
|
||||
});
|
||||
|
||||
if (!result)
|
||||
throw new TRPCError({
|
||||
message: `Failed to create board from source`,
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,8 +78,7 @@ export const configuredProviders = socialProviderList.reduce<
|
||||
Object.keys(acc).includes("google") &&
|
||||
acc[provider]
|
||||
) {
|
||||
const allowed = process.env.BETTER_AUTH_ALLOWED_DOMAINS
|
||||
?.split(",")
|
||||
const allowed = process.env.BETTER_AUTH_ALLOWED_DOMAINS?.split(",")
|
||||
.map((d) => d.trim().toLowerCase())
|
||||
.filter(Boolean);
|
||||
if (allowed && allowed.length > 0) {
|
||||
@@ -299,9 +298,8 @@ export const initAuth = (db: dbClient) => {
|
||||
}),
|
||||
]
|
||||
: []),
|
||||
// @todo: hasing is disabled due to a bug in the api key plugin
|
||||
apiKey({
|
||||
disableKeyHashing: true,
|
||||
enableSessionForAPIKeys: true,
|
||||
rateLimit: {
|
||||
enabled: true,
|
||||
timeWindow: 1000 * 60, // 1 minute
|
||||
@@ -365,8 +363,7 @@ export const initAuth = (db: dbClient) => {
|
||||
// Fall through to any additional checks below
|
||||
}
|
||||
// Enforce allowed domains (OIDC/social) if configured
|
||||
const allowed = process.env.BETTER_AUTH_ALLOWED_DOMAINS
|
||||
?.split(",")
|
||||
const allowed = process.env.BETTER_AUTH_ALLOWED_DOMAINS?.split(",")
|
||||
.map((d) => d.trim().toLowerCase())
|
||||
.filter(Boolean);
|
||||
if (allowed && allowed.length > 0) {
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
},
|
||||
"prettier": "@kan/prettier-config",
|
||||
"dependencies": {
|
||||
"date-fns": "^4.1.0",
|
||||
"jose": "^6.1.2",
|
||||
"nanoid": "^5.0.9",
|
||||
"next-runtime-env": "^1.7.2"
|
||||
|
||||
63
packages/shared/src/utils/dueDateFilters.ts
Normal file
63
packages/shared/src/utils/dueDateFilters.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { addDays, endOfDay, startOfDay } from "date-fns";
|
||||
|
||||
export type DueDateFilterKey =
|
||||
| "overdue"
|
||||
| "today"
|
||||
| "tomorrow"
|
||||
| "next-week"
|
||||
| "next-month"
|
||||
| "no-due-date";
|
||||
|
||||
export interface DueDateFilter {
|
||||
startDate?: Date;
|
||||
endDate?: Date;
|
||||
hasNoDueDate?: boolean;
|
||||
}
|
||||
|
||||
export const convertDueDateFiltersToRanges = (
|
||||
filters: DueDateFilterKey[],
|
||||
): DueDateFilter[] => {
|
||||
if (!filters.length) return [];
|
||||
|
||||
const today = startOfDay(new Date());
|
||||
const tomorrow = addDays(today, 1);
|
||||
const nextWeekEnd = addDays(today, 8);
|
||||
const nextMonthEnd = addDays(today, 31);
|
||||
|
||||
return filters.map((filter) => {
|
||||
switch (filter) {
|
||||
case "overdue":
|
||||
return {
|
||||
endDate: today,
|
||||
};
|
||||
case "today":
|
||||
return {
|
||||
startDate: today,
|
||||
endDate: endOfDay(today),
|
||||
};
|
||||
case "tomorrow":
|
||||
return {
|
||||
startDate: tomorrow,
|
||||
endDate: endOfDay(tomorrow),
|
||||
};
|
||||
case "next-week": {
|
||||
return {
|
||||
startDate: today,
|
||||
endDate: nextWeekEnd,
|
||||
};
|
||||
}
|
||||
case "next-month": {
|
||||
return {
|
||||
startDate: nextWeekEnd,
|
||||
endDate: nextMonthEnd,
|
||||
};
|
||||
}
|
||||
case "no-due-date":
|
||||
return {
|
||||
hasNoDueDate: true,
|
||||
};
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -2,3 +2,4 @@ export * from "./generateUID";
|
||||
export * from "./generateSlug";
|
||||
export * from "./subscriptions";
|
||||
export * from "./email";
|
||||
export * from "./dueDateFilters";
|
||||
|
||||
Reference in New Issue
Block a user