• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / storage / 25738155938

12 May 2026 01:38PM UTC coverage: 39.251% (-35.1%) from 74.366%
25738155938

Pull #1094

github

web-flow
Merge 0f3efcca0 into defbbb616
Pull Request #1094: feat: embedded vector store

2188 of 6152 branches covered (35.57%)

Branch coverage included in aggregate %.

88 of 280 new or added lines in 6 files covered. (31.43%)

3689 existing lines in 165 files now uncovered.

4312 of 10408 relevant lines covered (41.43%)

34.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

5.71
/src/http/plugins/jwt.ts
1
import { verifyJWT, verifyJWTWithCache } from '@internal/auth'
2
import { getJwtSecret } from '@internal/database'
3
import { ERRORS } from '@internal/errors'
4
import { FastifyInstance } from 'fastify'
5
import fastifyPlugin from 'fastify-plugin'
6
import { JWTPayload } from 'jose'
7
import { getConfig } from '../../config'
8

9
declare module 'fastify' {
10
  interface FastifyRequest {
11
    isAuthenticated: boolean
12
    jwt: string
13
    jwtPayload?: JWTPayload & { role?: string }
14
    owner?: string
15
  }
16

17
  interface FastifyContextConfig {
18
    allowInvalidJwt?: boolean
19
  }
20
}
21

22
interface JWTPluginOptions {
23
  enforceJwtRoles?: string[]
24
  skipIfAlreadyAuthenticated?: boolean
25
}
26

27
const { jwtCachingEnabled } = getConfig()
3✔
28

29
const BEARER = /^Bearer\s+/i
3✔
30

31
const jwtPlugin = fastifyPlugin<JWTPluginOptions>(
3✔
32
  async (fastify, opts) => {
UNCOV
33
    fastify.decorateRequest('jwt', '')
×
UNCOV
34
    fastify.decorateRequest('jwtPayload', undefined)
×
35

UNCOV
36
    fastify.addHook('preHandler', async (request) => {
×
UNCOV
37
      if (opts.skipIfAlreadyAuthenticated && request.isAuthenticated && request.jwtPayload) {
×
38
        return
×
39
      }
40

UNCOV
41
      request.jwt = (request.headers.authorization || '').replace(BEARER, '')
×
42

UNCOV
43
      if (!request.jwt && request.routeOptions.config.allowInvalidJwt) {
×
UNCOV
44
        request.jwtPayload = { role: 'anon' }
×
UNCOV
45
        request.isAuthenticated = false
×
UNCOV
46
        return
×
47
      }
48

UNCOV
49
      const { secret, jwks } = await getJwtSecret(request.tenantId)
×
50

UNCOV
51
      try {
×
UNCOV
52
        const payload = await (jwtCachingEnabled
×
53
          ? verifyJWTWithCache(request.jwt, secret, jwks || null)
×
54
          : verifyJWT(request.jwt, secret, jwks || null))
×
55

UNCOV
56
        request.jwtPayload = payload
×
UNCOV
57
        request.owner = payload.sub
×
UNCOV
58
        request.isAuthenticated = true
×
59
      } catch (e) {
60
        request.jwtPayload = { role: 'anon' }
×
61
        request.isAuthenticated = false
×
62

63
        if (request.routeOptions.config.allowInvalidJwt) {
×
64
          return
×
65
        }
66
        const err = e as Error
×
67
        throw ERRORS.AccessDenied(err.message, err)
×
68
      }
69
    })
70

UNCOV
71
    if (opts.enforceJwtRoles && opts.enforceJwtRoles.length > 0) {
×
UNCOV
72
      fastify.register(enforceJwtRole, {
×
73
        roles: opts.enforceJwtRoles,
74
      })
75
    }
76
  },
77
  { name: 'auth-jwt' }
78
)
79

80
interface EnforceJWTRoleOptions {
81
  roles: string[]
82
}
83

84
export const enforceJwtRole = fastifyPlugin<EnforceJWTRoleOptions>(
3✔
85
  async (fastify, opts) => {
UNCOV
86
    fastify.addHook('preHandler', async (request) => {
×
UNCOV
87
      if (!request.isAuthenticated) {
×
88
        throw ERRORS.AccessDenied('Access denied: JWT is not authenticated').withStatusCode(403)
×
89
      }
90

UNCOV
91
      const hasRoles = request.jwtPayload?.role && opts.roles.includes(request.jwtPayload.role)
×
92

UNCOV
93
      if (!hasRoles) {
×
UNCOV
94
        throw ERRORS.AccessDenied(`Access denied: Invalid role`).withStatusCode(403)
×
95
      }
96
    })
97
  },
98
  { name: 'allow-invalid-jwt' }
99
)
100

101
export function registerJwtAuth(fastify: FastifyInstance, opts: JWTPluginOptions = {}) {
×
UNCOV
102
  fastify.addHook('onRoute', (routeOptions) => {
×
UNCOV
103
    routeOptions.schema = routeOptions.schema || {}
×
UNCOV
104
    routeOptions.schema.security = [{ bearerAuth: [] }]
×
105
  })
UNCOV
106
  fastify.register(jwtPlugin, opts)
×
107
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc