fix: HoverPreview not showing on collaborative editing teams

types
This commit is contained in:
Tom Moor
2021-12-05 19:31:08 -08:00
parent ce2a58e83b
commit 6e371f0d03
13 changed files with 111 additions and 88 deletions

View File

@@ -1,51 +1,52 @@
import crypto from "crypto";
import { addMinutes, subMinutes } from "date-fns";
import fetch from "fetch-with-proxy";
import { Request } from "koa";
import { Context } from "koa";
import { OAuthStateMismatchError } from "../errors";
import { getCookieDomain } from "./domains";
export class StateStore {
key = "state";
store = (req: Request, callback: () => void) => {
store = (
ctx: Context,
callback: (err: Error | null, state: string) => void
) => {
// Produce a random string as state
const state = crypto.randomBytes(8).toString("hex");
// @ts-expect-error ts-migrate(2339) FIXME: Property 'cookies' does not exist on type 'Request... Remove this comment to see the full error message
req.cookies.set(this.key, state, {
ctx.cookies.set(this.key, state, {
httpOnly: false,
expires: addMinutes(new Date(), 10),
domain: getCookieDomain(req.hostname),
domain: getCookieDomain(ctx.hostname),
});
// @ts-expect-error ts-migrate(2554) FIXME: Expected 0 arguments, but got 2.
callback(null, state);
};
verify = (req: Request, providedState: string, callback: () => void) => {
// @ts-expect-error ts-migrate(2339) FIXME: Property 'cookies' does not exist on type 'Request... Remove this comment to see the full error message
const state = req.cookies.get(this.key);
verify = (
ctx: Context,
providedState: string,
callback: (err: Error | null, success?: boolean) => void
) => {
const state = ctx.cookies.get(this.key);
if (!state) {
return callback(
// @ts-expect-error ts-migrate(2554) FIXME: Expected 0 arguments, but got 1.
new OAuthStateMismatchError("State not return in OAuth flow")
OAuthStateMismatchError("State not return in OAuth flow")
);
}
// @ts-expect-error ts-migrate(2339) FIXME: Property 'cookies' does not exist on type 'Request... Remove this comment to see the full error message
req.cookies.set(this.key, "", {
ctx.cookies.set(this.key, "", {
httpOnly: false,
expires: subMinutes(new Date(), 1),
domain: getCookieDomain(req.hostname),
domain: getCookieDomain(ctx.hostname),
});
if (state !== providedState) {
// @ts-expect-error ts-migrate(2554) FIXME: Expected 0 arguments, but got 1.
return callback(new OAuthStateMismatchError());
return callback(OAuthStateMismatchError());
}
// @ts-expect-error ts-migrate(2554) FIXME: Expected 0 arguments, but got 2.
callback(null, true);
};
}