Skip to content

Commit

Permalink
Moved away from extending CookieSerializeOptions to module declaration (
Browse files Browse the repository at this point in the history
  • Loading branch information
chmking authored Oct 25, 2024
1 parent 9efac6e commit a9898e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@chmking/h3-csrf",
"description": "CSRF token middleware for H3",
"version": "1.0.2",
"version": "1.0.3",
"author": "Christopher King <[email protected]>",
"repository": {
"type": "git",
Expand Down
20 changes: 13 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ declare module 'http' {
}
}

declare module 'cookie-es' {
interface CookieSerializeOptions {
name?: string
}
}

type HTTPMethod =
| 'GET'
| 'HEAD'
Expand All @@ -30,13 +36,9 @@ type HTTPMethod =

const PayloadMethods: HTTPMethod[] = ['PATCH', 'POST', 'PUT', 'DELETE']

export interface CookieOptions extends CookieSerializeOptions {
name?: string
}

export interface Options {
verifiedMethods?: Array<HTTPMethod>
cookie?: CookieOptions
cookie?: CookieSerializeOptions
}

const defaultOptions: Options = {
Expand Down Expand Up @@ -103,12 +105,16 @@ export function csrf(options: Options = {}) {
}
}

function getSecret(event: H3Event, options: CookieOptions) {
function getSecret(event: H3Event, options: CookieSerializeOptions) {
const cookie = getCookie(event, options.name)
return cookie
}

function setSecret(event: H3Event, secret: string, options: CookieOptions) {
function setSecret(
event: H3Event,
secret: string,
options: CookieSerializeOptions
) {
setCookie(event, options.name, secret, options)
}

Expand Down

0 comments on commit a9898e2

Please sign in to comment.