Hardik Verma
Hardik Verma11mo ago

Need help with action retrier

I’ve got the suggestion from Jamie to use Action retrier, but I want to trigger it from next js server actions, could not find any documentation for that, so reaching out here, I am unable to pass the token of clerk to it so that it can property authenticate and run these actions, where can i get the help from:
No description
3 Replies
erquhart
erquhart11mo ago
Retrier is using scheduling to retry the action, and scheduled functions don't have access to auth info - you'll need to pass the auth info into the function. Looking at the repo, though, I'm honestly not sure how auth is expected to be used here since the retrier is being invoked from the client. I'm going to noodle on that a bit. I believe your best bet here is to use retrier on scheduled actions. So, for any authenticated action that you want to retry, call another action that does the auth check, and then passes the authenticated user info (not the token) to a scheduled function that uses retrier, eg.,
// handler body
// use ctx.auth to get the authenticated user's id, then schedule the action that should use retrier

ctx.scheduler.runAfter(
0,
api.retrier.runAction,
{
action: 'my:action',
actionArgs: { ...args, userId; authenticatedUserId } },
},
)
// handler body
// use ctx.auth to get the authenticated user's id, then schedule the action that should use retrier

ctx.scheduler.runAfter(
0,
api.retrier.runAction,
{
action: 'my:action',
actionArgs: { ...args, userId; authenticatedUserId } },
},
)
cc/ @james in case I'm missing something and there's a better way with this lib
Indy
Indy11mo ago
I would restructure the code to not call the action retrier directly. You probably want a different function that handles the request from next, checks auth and then calls the action retrier with the relevant action.
erquhart
erquhart11mo ago
That's what I'm recommending as well, but you said it much more clearly lol Ah but no need to schedule, I see that now - you can just call the action via ctx.runAction()

Did you find this page helpful?