Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/helper/cookie/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,5 +430,19 @@ describe('Cookie Middleware', () => {
expect(res.status).toBe(200)
expect(await res.text()).toBe('choco')
})

app.get('/delete-cookie-with-prefix', (c) => {
const deleted = deleteCookie(c, 'delicious_cookie', { prefix: 'secure' })
return c.text(deleted || '')
})

it('Get deleted value with prefix', async () => {
const cookieString = '__Secure-delicious_cookie=choco'
const req = new Request('http://localhost/delete-cookie-with-prefix')
req.headers.set('Cookie', cookieString)
const res = await app.request(req)
expect(res.status).toBe(200)
expect(await res.text()).toBe('choco')
})
})
})
6 changes: 3 additions & 3 deletions src/helper/cookie/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { Cookie, CookieOptions, CookiePrefixOptions, SignedCookie } from '.
interface GetCookie {
(c: Context, key: string): string | undefined
(c: Context): Cookie
(c: Context, key: string, prefixOptions: CookiePrefixOptions): string | undefined
(c: Context, key: string, prefixOptions?: CookiePrefixOptions): string | undefined
}

interface GetSignedCookie {
Expand All @@ -20,7 +20,7 @@ interface GetSignedCookie {
c: Context,
secret: string | BufferSource,
key: string,
prefixOptions: CookiePrefixOptions
prefixOptions?: CookiePrefixOptions
): Promise<string | undefined | false>
}

Expand Down Expand Up @@ -124,7 +124,7 @@ export const setSignedCookie = async (
}

export const deleteCookie = (c: Context, name: string, opt?: CookieOptions): string | undefined => {
const deletedCookie = getCookie(c, name)
const deletedCookie = getCookie(c, name, opt?.prefix)
setCookie(c, name, '', { ...opt, maxAge: 0 })
return deletedCookie
}
Loading