mirror of
https://github.com/djdevin/recflare.git
synced 2026-09-08 22:51:30 -07:00
authentication improvements
This commit is contained in:
@@ -50,7 +50,7 @@ async function authedId(c: Context<App>): Promise<number | null> {
|
||||
if (!authHeader.toLowerCase().startsWith('bearer ')) return null
|
||||
|
||||
const token = authHeader.slice('Bearer '.length)
|
||||
const accountId = await validateAndGetAccountId(token)
|
||||
const accountId = await validateAndGetAccountId(token, await c.env.JWT_SECRET.get())
|
||||
if (!accountId) return null
|
||||
|
||||
const id = Number.parseInt(accountId, 10)
|
||||
@@ -599,12 +599,9 @@ const app = new Hono<App>({ strict: false })
|
||||
if (room.CreatorAccountId === accountId) return c.json(true)
|
||||
|
||||
// Otherwise the caller needs a room role at least as high as requested.
|
||||
const roles = Array.isArray(room.Roles)
|
||||
? (room.Roles as Array<Record<string, unknown>>)
|
||||
: []
|
||||
const roles = Array.isArray(room.Roles) ? (room.Roles as Array<Record<string, unknown>>) : []
|
||||
const hasRole = roles.some(
|
||||
(r) =>
|
||||
r.AccountId === accountId && typeof r.Role === 'number' && r.Role >= (role || 0)
|
||||
(r) => r.AccountId === accountId && typeof r.Role === 'number' && r.Role >= (role || 0)
|
||||
)
|
||||
return c.json(hasRole)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user