trigger.dev icon indicating copy to clipboard operation
trigger.dev copied to clipboard

feature request: Supabase Management integration available to local supabase as well

Open arika0093 opened this issue 2 years ago • 3 comments

Current issue

  1. run supabase locally: npx supabase start
  2. create a job using the Supabase Management SDK on local.
  3. the following error occurs and the integration is not created.
Error: Failed to run query: Unauthorized (401): invalid signature
    at SupabaseManagementAPI.createResponseError_fn (/workspaces/nextjs-supabase-triggerdev-test/node_modules/supabase-management-js/dist/index.js:1102:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async SupabaseManagementAPI.runQuery (/workspaces/nextjs-supabase-triggerdev-test/node_modules/supabase-management-js/dist/index.js:626:13)
    at async executeTask (/workspaces/nextjs-supabase-triggerdev-test/node_modules/@trigger.dev/sdk/dist/index.js:930:24)
    at async ioConnection.<computed> [as runQuery] (/workspaces/nextjs-supabase-triggerdev-test/node_modules/@trigger.dev/sdk/dist/index.js:506:18)
    at async Object.register (/workspaces/nextjs-supabase-triggerdev-test/node_modules/@trigger.dev/supabase/dist/index.js:540:28)
    at async ExternalSource.register (/workspaces/nextjs-supabase-triggerdev-test/node_modules/@trigger.dev/sdk/dist/index.js:1810:21)
    at async Object.run (/workspaces/nextjs-supabase-triggerdev-test/node_modules/@trigger.dev/sdk/dist/index.js:1497:25)
    at async #executeJob (/workspaces/nextjs-supabase-triggerdev-test/node_modules/@trigger.dev/sdk/dist/index.js:1600:20)
    at async TriggerClient.handleRequest (/workspaces/nextjs-supabase-triggerdev-test/node_modules/@trigger.dev/sdk/dist/index.js:1312:25)
    at async handler (/workspaces/nextjs-supabase-triggerdev-test/node_modules/@trigger.dev/nextjs/dist/index.js:32:22)

Cause

The supabase-management-js used internally assumes the use of the cloud version. Therefore, it is not possible to issue a webhook to a locally hosted supabase. Furthermore, there is no API to enable webhooks in local supabase.

Suggestion for improvement

case 1

  1. when creating a Supabase Management class, the connection string to the supabase-db can be passed as an argument.
  2. the argument of 1. is given, execute the query of createTriggerQuery directly.

case 2

case 1 is preferable because it can be automated, but if SQL execution is not preferred, this option is also available.

  1. when creating a Supabase Management class, you can pass an option to omit automatic webhook create as an argument.
  2. the argument of 1. is given, instead of executed the query of createTriggerQuery, output it to the log (to be executed manually by the user)

arika0093 avatar Aug 31 '23 10:08 arika0093

Any progress with this? i have the same issue and cannot test it locally

I manage some progress, at least I get to have it well deployed but when I do some insert in the db it does not work:

new Job(client, {
  id: 'my-job',
  name: 'My job',
  version: '0.0.1',
  trigger: db.onInserted({
    schema: 'public',
    table: 'users',
  }),
  run: async (payload, io, ctx) => {
    console.log('added users')
    io.logger.info('Add customers')
    io.logger.info('payload', payload)
    io.logger.info('ctx', ctx)
  },
})

amm297 avatar Nov 03 '23 10:11 amm297

Self-hosted Supabase does not use the Management API (ref).

It does however use Postgres Meta, but I'm not sure if that would be able to fill the gap.

The best would be if Supabase added support for the Management API in their self-hosted version.

estubmo avatar Apr 13 '24 09:04 estubmo

I am also interested in this. I could get the payload to hit trigger.dev but without being able to hash the the webhook's secret key in the header I couldn't do anything with the payload. I just can see it and the trigger fails.

I was thinking of implementing Auth.js from Supabase in my local instance and seeing if that has any luck.

Peterksharma avatar Apr 29 '24 15:04 Peterksharma