- You requested to permanantly delete your Outline account. Please - enter the code below to confirm your account deletion. + You requested to permanantly delete your {env.APP_NAME} account. + Please enter the code below to confirm your account deletion.
diff --git a/server/emails/templates/ExportSuccessEmail.tsx b/server/emails/templates/ExportSuccessEmail.tsx
index a992790f91..fed860e558 100644
--- a/server/emails/templates/ExportSuccessEmail.tsx
+++ b/server/emails/templates/ExportSuccessEmail.tsx
@@ -1,4 +1,5 @@
import * as React from "react";
+import env from "@server/env";
import { NotificationSetting } from "@server/models";
import BaseEmail from "./BaseEmail";
import Body from "./components/Body";
@@ -39,7 +40,7 @@ export default class ExportSuccessEmail extends BaseEmail
- +
diff --git a/server/emails/templates/InviteEmail.tsx b/server/emails/templates/InviteEmail.tsx index a80f0fffee..8b2aeebfab 100644 --- a/server/emails/templates/InviteEmail.tsx +++ b/server/emails/templates/InviteEmail.tsx @@ -1,4 +1,5 @@ import * as React from "react"; +import env from "@server/env"; import BaseEmail from "./BaseEmail"; import Body from "./components/Body"; import Button from "./components/Button"; @@ -26,7 +27,7 @@ export default class InviteEmail extends BaseEmail- {actorName} ({actorEmail}) has invited you to join Outline, a place - for your team to build and share knowledge. + {actorName} ({actorEmail}) has invited you to join {env.APP_NAME}, a + place for your team to build and share knowledge.
diff --git a/server/emails/templates/InviteReminderEmail.tsx b/server/emails/templates/InviteReminderEmail.tsx
index b06f83ecbf..9ff6274c0f 100644
--- a/server/emails/templates/InviteReminderEmail.tsx
+++ b/server/emails/templates/InviteReminderEmail.tsx
@@ -1,4 +1,5 @@
import * as React from "react";
+import env from "@server/env";
import BaseEmail from "./BaseEmail";
import Body from "./components/Body";
import Button from "./components/Button";
@@ -27,7 +28,7 @@ export default class InviteReminderEmail extends BaseEmail
This is just a quick reminder that {actorName} ({actorEmail})
- invited you to join them in the {teamName} team on Outline, a place
- for your team to build and share knowledge.
+ invited you to join them in the {teamName} team on {env.APP_NAME}, a
+ place for your team to build and share knowledge.
If you haven't signed up yet, you can do so here: Click the button below to sign in to Outline. Click the button below to sign in to {env.APP_NAME}.
diff --git a/server/emails/templates/WelcomeEmail.tsx b/server/emails/templates/WelcomeEmail.tsx
index d8fe13fbaa..3fb1cd3e42 100644
--- a/server/emails/templates/WelcomeEmail.tsx
+++ b/server/emails/templates/WelcomeEmail.tsx
@@ -1,4 +1,5 @@
import * as React from "react";
+import env from "@server/env";
import BaseEmail from "./BaseEmail";
import Body from "./components/Body";
import Button from "./components/Button";
@@ -19,18 +20,18 @@ type Props = {
*/
export default class WelcomeEmail extends BaseEmail Outline is a place for your team to build and share knowledge.
+ {env.APP_NAME} is a place for your team to build and share
+ knowledge.
+
To get started, head to the home screen and try creating a
collection to help document your processes, create playbooks, or
@@ -60,7 +64,7 @@ ${teamUrl}/home
- Outline
+ {env.APP_NAME}
Twitter
diff --git a/server/emails/templates/components/Header.tsx b/server/emails/templates/components/Header.tsx
index 671b1ed009..f0848abb92 100644
--- a/server/emails/templates/components/Header.tsx
+++ b/server/emails/templates/components/Header.tsx
@@ -14,7 +14,7 @@ export default () => {
{
},
jest.fn()
);
- expect(state.user.id).toEqual(user.id);
+ expect(state.auth.user.id).toEqual(user.id);
});
it("should return error with invalid token", async () => {
@@ -68,7 +68,7 @@ describe("Authentication middleware", () => {
},
jest.fn()
);
- expect(state.user.id).toEqual(user.id);
+ expect(state.auth.user.id).toEqual(user.id);
});
it("should return error with invalid API key", async () => {
const state = {} as DefaultState;
@@ -133,7 +133,7 @@ describe("Authentication middleware", () => {
},
jest.fn()
);
- expect(state.user.id).toEqual(user.id);
+ expect(state.auth.user.id).toEqual(user.id);
});
it("should allow passing auth token in body params", async () => {
@@ -154,7 +154,7 @@ describe("Authentication middleware", () => {
},
jest.fn()
);
- expect(state.user.id).toEqual(user.id);
+ expect(state.auth.user.id).toEqual(user.id);
});
it("should return an error for suspended users", async () => {
diff --git a/server/middlewares/authentication.ts b/server/middlewares/authentication.ts
index b0d5778533..278d89008a 100644
--- a/server/middlewares/authentication.ts
+++ b/server/middlewares/authentication.ts
@@ -5,13 +5,13 @@ import tracer, {
getRootSpanFromRequestContext,
} from "@server/logging/tracer";
import { User, Team, ApiKey } from "@server/models";
+import { AppContext, AuthenticationType } from "@server/types";
import { getUserForJWT } from "@server/utils/jwt";
import {
AuthenticationError,
AuthorizationError,
UserSuspendedError,
} from "../errors";
-import { ContextWithState, AuthenticationType } from "../types";
type AuthenticationOptions = {
/* An admin user role is required to access the route */
@@ -26,7 +26,7 @@ type AuthenticationOptions = {
};
export default function auth(options: AuthenticationOptions = {}) {
- return async function authMiddleware(ctx: ContextWithState, next: Next) {
+ return async function authMiddleware(ctx: AppContext, next: Next) {
let token;
const authorizationHeader = ctx.request.get("authorization");
@@ -61,11 +61,12 @@ export default function auth(options: AuthenticationOptions = {}) {
throw AuthenticationError("Authentication required");
}
- let user: User | null | undefined;
+ let user: User | null;
+ let type: AuthenticationType;
if (token) {
if (ApiKey.match(String(token))) {
- ctx.state.authType = AuthenticationType.API;
+ type = AuthenticationType.API;
let apiKey;
try {
@@ -96,7 +97,7 @@ export default function auth(options: AuthenticationOptions = {}) {
throw AuthenticationError("Invalid API key");
}
} else {
- ctx.state.authType = AuthenticationType.APP;
+ type = AuthenticationType.APP;
user = await getUserForJWT(String(token));
}
@@ -129,19 +130,24 @@ export default function auth(options: AuthenticationOptions = {}) {
Logger.error("Failed to update user activeAt", err);
});
- ctx.state.token = String(token);
- ctx.state.user = user;
+ ctx.state.auth = {
+ user,
+ token: String(token),
+ type,
+ };
if (tracer) {
addTags(
{
"request.userId": user.id,
"request.teamId": user.teamId,
- "request.authType": ctx.state.authType,
+ "request.authType": type,
},
getRootSpanFromRequestContext(ctx)
);
}
+ } else {
+ ctx.state.auth = {};
}
return next();
diff --git a/server/middlewares/rateLimiter.ts b/server/middlewares/rateLimiter.ts
index aaedc36102..d302e61432 100644
--- a/server/middlewares/rateLimiter.ts
+++ b/server/middlewares/rateLimiter.ts
@@ -2,6 +2,7 @@ import { Context, Next } from "koa";
import { defaults } from "lodash";
import env from "@server/env";
import { RateLimitExceededError } from "@server/errors";
+import Logger from "@server/logging/Logger";
import Metrics from "@server/logging/Metrics";
import Redis from "@server/redis";
import RateLimiter from "@server/utils/RateLimiter";
@@ -27,19 +28,23 @@ export function defaultRateLimiter() {
try {
await limiter.consume(key);
} catch (rateLimiterRes) {
- ctx.set("Retry-After", `${rateLimiterRes.msBeforeNext / 1000}`);
- ctx.set("RateLimit-Limit", `${limiter.points}`);
- ctx.set("RateLimit-Remaining", `${rateLimiterRes.remainingPoints}`);
- ctx.set(
- "RateLimit-Reset",
- `${new Date(Date.now() + rateLimiterRes.msBeforeNext)}`
- );
+ if (rateLimiterRes.msBeforeNext) {
+ ctx.set("Retry-After", `${rateLimiterRes.msBeforeNext / 1000}`);
+ ctx.set("RateLimit-Limit", `${limiter.points}`);
+ ctx.set("RateLimit-Remaining", `${rateLimiterRes.remainingPoints}`);
+ ctx.set(
+ "RateLimit-Reset",
+ `${new Date(Date.now() + rateLimiterRes.msBeforeNext)}`
+ );
- Metrics.increment("rate_limit.exceeded", {
- path: ctx.path,
- });
+ Metrics.increment("rate_limit.exceeded", {
+ path: ctx.path,
+ });
- throw RateLimitExceededError();
+ throw RateLimitExceededError();
+ } else {
+ Logger.error("Rate limiter error", rateLimiterRes);
+ }
}
return next();
diff --git a/server/middlewares/transaction.ts b/server/middlewares/transaction.ts
index 9291b3e9dd..58ca1b434f 100644
--- a/server/middlewares/transaction.ts
+++ b/server/middlewares/transaction.ts
@@ -1,12 +1,7 @@
-import { Context, Next } from "koa";
+import { Next } from "koa";
import { Transaction } from "sequelize";
import { sequelize } from "@server/database/sequelize";
-
-export type TransactionContext = Context & {
- state: Context["state"] & {
- transaction: Transaction;
- };
-};
+import { AppContext } from "@server/types";
/**
* Middleware that wraps a route in a database transaction, useful for mutations
@@ -16,7 +11,7 @@ export type TransactionContext = Context & {
* @returns The middleware function.
*/
export function transaction() {
- return async function transactionMiddleware(ctx: Context, next: Next) {
+ return async function transactionMiddleware(ctx: AppContext, next: Next) {
await sequelize.transaction(async (t: Transaction) => {
ctx.state.transaction = t;
return next();
diff --git a/server/middlewares/validate.ts b/server/middlewares/validate.ts
index 2c0684352b..24f7e55ef0 100644
--- a/server/middlewares/validate.ts
+++ b/server/middlewares/validate.ts
@@ -1,16 +1,20 @@
import { Next } from "koa";
-import { z } from "zod";
+import { z, ZodError } from "zod";
import { ValidationError } from "@server/errors";
-import { APIContext } from "@server/types";
+import { APIContext, BaseReq } from "@server/types";
-export default function validate