fix: HoverPreview not showing on collaborative editing teams
types
This commit is contained in:
@@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user