import { FastifyPluginCallback } from "fastify";
declare module "fastify" {
interface FastifyInstance {
unsignCookie(value: string): {
valid: boolean;
renew: boolean;
value: string | null;
};
parseCookie(cookieHeader: string): {
[key: string]: string;
};
}
interface FastifyRequest {
cookies: { [cookieName: string]: string };
unsignCookie(value: string): {
valid: boolean;
renew: boolean;
value: string | null;
};
}
export type setCookieWrapper = (
name: string,
value: string,
options?: CookieSerializeOptions
) => FastifyReply;
interface FastifyReply {
setCookie(
name: string,
value: string,
options?: CookieSerializeOptions
): this;
cookie(name: string, value: string, options?: CookieSerializeOptions): this;
clearCookie(name: string, options?: CookieSerializeOptions): this;
unsignCookie(value: string): {
valid: boolean;
renew: boolean;
value: string | null;
};
}
}
export interface CookieSerializeOptions {
domain?: string;
encode?(val: string): string;
expires?: Date;
httpOnly?: boolean;
maxAge?: number;
path?: string;
sameSite?: boolean | "lax" | "strict" | "none";
secure?: boolean;
signed?: boolean;
}
interface Signer {
sign: (input: string) => string;
unsign: (input: string) => {
valid: boolean;
renew: boolean;
value: string | null;
};
}
export interface FastifyCookieOptions {
secret?: string | string[] | Signer;
parseOptions?: CookieSerializeOptions;
}
declare const fastifyCookie: FastifyPluginCallback<
NonNullable<FastifyCookieOptions>
>;
export default fastifyCookie;
export { fastifyCookie };