Proper way to the authorize the user in an Inngest function?
Hey there, looking for some help wrapping my head around getting the user session in an Inngest function. I have my project updated to use the newer
getClaims
method also. In the following code the getClaims
data is empty which is expected in this scope. What would be the proper way to get the session validated in this scope to perform CRUD operations on the tables?
Inngest function
API route that triggers the Inngest function
5 Replies
Is there a way to get the access token out of this? I could use that to create the client in Inngest
You would just pass the access token from the API route to the
inngest
call as a data property.Hey, good morning! Thank you for that info! Quick follow up, is there a way to get that access token from a getClaims call? Tried looking this up in the docs but not a lot of references to getClaims in there
The Inngest functions are going to run asynchronously, so you cannot guarantee that the token will still be valid when it runs. Likely it will, but you're relying on luck of timing for correctness, and that's never a good pattern. Best pattern here is to pass the supabase user ID to the Inngest function, and have it run queries as the service account and use the user_id to your
where
clauses to restrict the access as you need.Sorry for the late reply just saw this. Thanks for that feedback!
I'll implement something like that instead