All guidesDeep-dive articles

Vercel eve session authorization

How do I isolate sessions by tenant in a Vercel eve agent?

By Ohad Krispin, founder of VibeRaven · LinkedIn

Short answer

Keep a server-side record tying each eve session ID to an organization. Check the authenticated user's current membership before forwarding any session-specific request, including streams and cancel requests. eve route authentication verifies the caller, and your app supplies the session ownership check.

On this page

Bind session IDs to verified memberships

  1. 1
    When an authenticated user starts a session, verify their membership in the selected organization and save the eve session ID with that organization's ID. Complete the binding before returning the ID to the client. Store a user ID too if sessions are personal within an organization.
  2. 2
    Save this as eve-session-access.test.mjs and run node --test eve-session-access.test.mjs. It models a team-shared session. Pass the verified principal and server-loaded binding in the app, and replace the fixture lookup with your current membership query.
    Code
    import assert from 'node:assert/strict';
    import { test } from 'node:test';
    
    async function mayUseSession({ principal, activeOrgId, binding, isMember }) {
      if (!principal?.userId || !binding || binding.orgId !== activeOrgId) {
        return false;
      }
      return await isMember(principal.userId, binding.orgId) === true;
    }
    
    test('a bound session requires current membership in the active organization', async () => {
      const members = new Set(['sam:acme']);
      const access = {
        principal: { userId: 'sam' },
        activeOrgId: 'acme',
        binding: { orgId: 'acme' },
        isMember: async (userId, orgId) => members.has(userId + ':' + orgId),
      };
      assert.equal(await mayUseSession(access), true);
      assert.equal(await mayUseSession({ ...access, activeOrgId: 'other' }), false);
      assert.equal(await mayUseSession({ ...access, binding: null }), false);
      assert.equal(await mayUseSession({ ...access, principal: null }), false);
      members.delete('sam:acme');
      assert.equal(await mayUseSession(access), false);
    });
  3. 3
    Put the check before forwarding follow-ups, stream connections and state-changing calls such as cancel or reset. If an app gateway enforces it, restrict the underlying eve routes to trusted callers so every user request goes through that check. Treat a requested organization ID as a selection to verify.
  4. 4
    Scope data access in tools using verified caller context and the server-side binding. On a resumed turn, ctx.session.auth.current can differ from auth.initiator. Define what a subagent or background job may do when there is no current user. For long-lived streams, decide how a membership change closes or invalidates an existing connection.

Official docs behind this checklist

FAQ for builders before launch

Can I use the session ID as proof that someone owns it?

Use the ID to look up the server-side binding. Authenticate the caller and check their current membership before streaming or accepting input.

Does Vercel OIDC make a session organization-scoped?

OIDC can authenticate the service reaching eve. The app still needs a verified user identity and an organization-specific authorization decision.