liveblocks icon indicating copy to clipboard operation
liveblocks copied to clipboard

Allow authentication to fail

Open m1guelpf opened this issue 1 year ago • 1 comments

Today, if the call to the authentication endpoint fails, it just keeps getting called forever. However, there are certain use-cases where you might want to handle the exception instead (such as when a user is trying to connect to a room they shouldn't have access to).

In order to make this customizable, we could add an extra key to the client config (onAuthError), which gets called with the exception thrown (or the response, if the error is a malformed response), and can return false to avoid retries (or anything else to retry anyway).

Digging through the codebase, this seems to be the function I'd add the logic to:

https://github.com/liveblocks/liveblocks/blob/6e5f2189c717426214577b658c838d01543e1001/packages/liveblocks-client/src/room.ts#L855-L863

m1guelpf avatar Jul 19 '22 14:07 m1guelpf

Hello, You make a good point; we should add a way to customize the logic retry. Your solution makes sense; another solution would be to add a list of error codes that should not retry. We will also have to think about if we want to add customization for the retry delay. I added a task to our backlog, we will update you when we have a clearer idea on the implementation.

ofoucherot avatar Jul 20 '22 14:07 ofoucherot

Hi! Just bumped into this issue and I'm checking in to see if there was any progress on this one.

npapagna avatar Dec 15 '22 20:12 npapagna

Ran into this today. Seems like a much needed capability.

TerminalFi avatar Jan 08 '23 18:01 TerminalFi

Hi folks! Are there any updates on this one? We would benefit a lot from having this. Thanks!

basicNew avatar Apr 20 '23 14:04 basicNew

Hello, we have this on our radar. I'm currently thinking about making some changes to holistically improve our client's stability and this would be a natural part of it. It may still take a bit of time before we can publish an updated version, but we're actively thinking about and working on this, so there is progress. We'll report back when we have more information to share — thanks for your patience!

nvie avatar Apr 20 '23 15:04 nvie

@m1guelpf @npapagna @TerminalFi @basicNew @jamesbvaughan @gcrespi Today, we launched Liveblocks 1.1, in which we holistically solved all known issues around connectivity. This is one of the issues that has been resolved by this release. Now, if you return a HTTP 401 or HTTP 403 in your backend, the client will respect this and stop hitting your auth backend and stop retrying. Thanks for reporting this bug, and for your patience while we implemented this! 🙏 Please let us know if you have any questions about this.

nvie avatar Jun 19 '23 15:06 nvie