Skip to content

Commit

Permalink
fix(dev): cookie names
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed May 16, 2024
1 parent c9bec3d commit 117aae5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/warm-cups-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"frog": patch
---

Changed devtools cookie names to be (more) unique to avoid localhost conflicts
39 changes: 25 additions & 14 deletions src/dev/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,20 @@ export function apiRoutes(
}
}>()
.use('*', async (c, next) => {
const userCookie = getCookie(c, 'user')
const fid = userCookie ? JSON.parse(userCookie).userFid : undefined
c.set('fid', fid)

const sessionCookie = secret
? await getSignedCookie(c, secret, 'session')
: getCookie(c, 'session')
const keypair = sessionCookie ? JSON.parse(sessionCookie) : undefined
c.set('keypair', keypair)
try {
const userCookie = getCookie(c, 'frog_user') ?? getCookie(c, 'user')
const fid = userCookie ? JSON.parse(userCookie).userFid : undefined
c.set('fid', fid)
} catch {}

try {
const sessionCookie = secret
? (await getSignedCookie(c, secret, 'frog_session')) ??
(await getSignedCookie(c, secret, 'session'))
: getCookie(c, 'frog_session') ?? getCookie(c, 'session')
const keypair = sessionCookie ? JSON.parse(sessionCookie) : undefined
c.set('keypair', keypair)
} catch {}

await next()
})
Expand Down Expand Up @@ -240,9 +245,15 @@ export function apiRoutes(
// 4. Save keypair in cookie
const value = JSON.stringify({ privateKey, publicKey })
if (secret)
await setSignedCookie(c, 'session', value, secret, defaultCookieOptions)
await setSignedCookie(
c,
'frog_session',
value,
secret,
defaultCookieOptions,
)
else
setCookie(c, 'session', value, {
setCookie(c, 'frog_session', value, {
...defaultCookieOptions,
httpOnly: true,
})
Expand All @@ -264,7 +275,7 @@ export function apiRoutes(

setCookie(
c,
'user',
'frog_user',
JSON.stringify({ token, userFid }),
defaultCookieOptions,
)
Expand All @@ -274,8 +285,8 @@ export function apiRoutes(
return c.json({ state })
})
.post('/auth/logout', async (c) => {
deleteCookie(c, 'session')
deleteCookie(c, 'user')
deleteCookie(c, 'frog_session')
deleteCookie(c, 'frog_user')
return c.json({ success: true })
})
.post(
Expand Down

0 comments on commit 117aae5

Please sign in to comment.