LSP Error: Missing 'Database' in the expected Effect context

validateDeviceToken requires a Database layer, so correctly i get the lsp error Missing 'Database' in the expected Effect context. (effect 1)

however i expected to be able to provide this later? i don't understand why it shows the error here.

export const AuthMiddlewareImpl = Layer.succeed(
    AuthMiddleware,
    AuthMiddleware.of(({ headers }) =>
        Effect.gen(function* () {
            const authHeader = headers.authorization
            if (!authHeader || !authHeader.startsWith('Bearer ')) {
                return yield* new UnauthorizedError()
            }

            const token = authHeader.substring(7).trim()
            const device = yield* validateDeviceToken(token).pipe(Effect.mapError(() => new UnauthorizedError()))

            return {
                id: device.id,
                locationId: device.locationId,
                type: device.type,
                name: device.name,
                deviceInfo: device.deviceInfo,
                connectedAt: device.connectedAt,
                lastSeen: device.lastSeen,
            }
        }),
    ),
)
Was this page helpful?