FG
๐Ÿ’ป Software๐ŸŒ Web & Full-Stack

feat: Authentication by Websocket

Freshover 1 year ago
Mar 14, 20260 views
Confidence Score87%
87%

Problem

Describe the feature you'd like to request We know that websocket do not use http headers, but during handshake http request can be used. Page 14 RFC 6455 https://www.rfc-editor.org/rfc/rfc6455#page-14 Current implementation sending these headers [code block] But I would like to add my custom headers here, eg Authorization. Connected reddit topic of other user: https://www.reddit.com/r/node/comments/117fgb5/trpc_correct_way_to_authorize_websocket/ Describe the solution you'd like to see This problem was solved in apollo client by [code block] in issue https://github.com/apollographql/apollo-client/issues/3967 or even better [code block] Probably when this function will return new headers (eg new bearer token will be added) we probably need restart all operations. [code block] so it seems to be complicated. Describe alternate solutions Alternatively we can think about `onOpen` function in `createWSClient` or if it is called after handshake, then maybe add function `beforeOpen` and give end user control over connecting and reconnecting when headers will be changed. Additional information I can try to contribute with this but need to know if this feature will be accepted and how to design it. ๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Contributing - [X] ๐Ÿ™‹โ€โ™‚๏ธ Yes, I'd be down to file a PR implementing this feature! I wrote article about approaches to this problem, so you can read details and discuss here which one should be preferred as official, and maybe instead of this feature we will ad

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
High Confidence Fix
84% confidence100% success rate3 verificationsLast verified Mar 14, 2026

Solution: feat: Authentication by Websocket

Low Risk

This feature would prove exceptionally valuable and impressive, particularly if it includes built-in support for managing refresh tokens. Its utility would be evident in single-page applications (SPAs) or across various mobile and desktop applications, thereby broadening the reach and application of tRPC.

84

Trust Score

3 verifications

100% success
  1. 1

    This feature would prove exceptionally valuable and impressive, particularly if

    This feature would prove exceptionally valuable and impressive, particularly if it includes built-in support for managing refresh tokens. Its utility would be evident in single-page applications (SPAs) or across various mobile and desktop applications, thereby broadening the reach and application of tRPC.

Validation

Resolved in trpc/trpc GitHub issue #3955. Community reactions: 2 upvotes.

Verification Summary

Worked: 3
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

trpctypescriptapi@trpc/clientโœ…-accepted-prs-welcome