Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dbauth-mw): Unset cookie instead of clearing #10502

Merged
merged 6 commits into from
Apr 26, 2024
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
2 changes: 2 additions & 0 deletions .changesets/10502.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- fix(dbauth-mw): Unset cookie instead of clearing (#10502) by @dac09
Updates dbAuth middleware implementation to _unset_ the cookies, instead of clearing them.
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,12 @@ describe('createDbAuthMiddleware()', () => {

const serverAuthContext = req.serverAuthContext.get()
expect(serverAuthContext).toBeNull()

expect(res.toResponse().headers.getSetCookie()).toEqual([
// Expired cookies, will be removed by browser
'session_8911=; Expires=Thu, 01 Jan 1970 00:00:00 GMT',
'auth-provider=; Expires=Thu, 01 Jan 1970 00:00:00 GMT',
])
})
it('handles a GET request with no cookies', async () => {
const request = new Request('http://localhost:8911/functions/no-cookie', {
Expand Down
7 changes: 4 additions & 3 deletions packages/auth-providers/dbAuth/middleware/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ export const createDbAuthMiddleware = ({
console.error(e, 'Error decrypting dbAuth cookie')
req.serverAuthContext.set(null)

// Clear the cookies, because decryption was invalid
res.cookies.clear(cookieNameCreator(cookieName))
res.cookies.clear('auth-provider')
// Note we have to use ".unset" and not ".clear"
// because we want to remove these cookies from the browser
res.cookies.unset(cookieNameCreator(cookieName))
res.cookies.unset('auth-provider')
}

return res
Expand Down
Loading