Lunn 🖤
Lunn 🖤•5w ago

Debugging Clerk Webhook Issues: "session.ended" event not triggering with Convex integration

This is the project I'm currently working on and the one in question: https://github.com/LunnS2/Self-Care-App.git Currently, the "session.ended" event is not being sent or attempted, so even though I log out on the client side, "isOnline" in the Convex database stays set to true. Another event that is causing some issues is "session.created", it's not always successful. With that said, what steps can I take to debug webhook failures and ensure Clerk events fire as expected? Also, if there are any other issues or suboptimal uses of Convex that you spot in any of my files, please let me know! I want to learn about Convex best practices and ensure my app works as expected and efficiently.
GitHub
GitHub - LunnS2/Self-Care-App
Contribute to LunnS2/Self-Care-App development by creating an account on GitHub.
No description
12 Replies
ballingt
ballingt•5w ago
re
Another event that is causing some issues is "session.created", it's not always successful. With that said, what steps can I take to debug webhook failures and ensure Clerk events fire as expected?
You should look at the Convex dashboard logs to see why this is failing, you should be able to find a stack trace with the error
Lunn 🖤
Lunn 🖤OP•5w ago
Thank you, it helped me solve my issues with "session.created". Now, I thought the client-side code I have for auth/log-in/sign-out — using @clerk/nextjs — would be enough to trigger session.ended, but the event is not registered in the clerk dashboard . Could I have some guidance on that too?
ballingt
ballingt•5w ago
I don't know what's up with that. Reading the docs, it does seem like session.ended is supposed to happen on logout https://clerk.com/blog/webhooks-getting-started
No description
ballingt
ballingt•5w ago
Are you subscribed to that event in your WebHook settings?
Lunn 🖤
Lunn 🖤OP•5w ago
No description
Lunn 🖤
Lunn 🖤OP•5w ago
I am, yes From a project I saw on youtube it used to work just like that, if I'm not mistaking I believe it's related to the way I have it on the client-side logic, but at least today, I wasn't able to figure that out So, I appreciate any kind of helpful feedback on this matter So thank you for your attention @ballingt :)
ballingt
ballingt•5w ago
@Lunn 🖤 you might add session.revoked and session.removed to see if those are being run instead
Lunn 🖤
Lunn 🖤OP•5w ago
I noticed on Clerk Logs that the one event being triggered on SignedOut is session.removed, is that okay? Should I use session.removed to declare when the user is offline instead? I think I have my answer due to what's bellow. However I'll wait for feedback! "session.ended: This event is fired when a user's session expires, is explicitly logged out, or is ended by the system. It's typically used when the session lifecycle comes to a natural end. session.removed: This event is fired when the session is removed by the system, usually as part of a user logout process or if the session is invalidated. This event might be more immediate and reliable for signaling when a user is actually logged out from the system."
ballingt
ballingt•5w ago
Ah yeah that looks good! Were there any docs we should update that encouraged use of session.ended instead of session.removed?
Lunn 🖤
Lunn 🖤OP•5w ago
Those two paragraphs I shared aren’t from any official documentation; they’re actually a snippet from an AI response I got while exploring whether session.removed would work for my use case. I’m not sure yet if one event is encouraged over the other—perhaps it depends on the scenario or goal. I don’t have the answer yet for why session.ended isn’t firing. I specifically asked about it on the Clerk Discord server, and for now: "As for why the event isn't firing, I'll have to test this further myself to see if I can replicate the behavior as there could be a few underlying reasons as to why this isn't being captured"
ballingt
ballingt•5w ago
I'd look for Clerk docs on this (or just the webhook event descriptions), but if those events are firing when you want them then that seems like the thing to use. Then if that behavior changes in the future Clerk will be sure to announce it.
Lunn 🖤
Lunn 🖤OP•5w ago
That's a very good advice. I did read documentation. However, the link to Clerk's official documentation on webhook events seems to have changed or is currently unavailable. So I can't read the official descriptions

Did you find this page helpful?