crossws icon indicating copy to clipboard operation
crossws copied to clipboard

docs: add auth and context

Open sandros94 opened this issue 11 months ago • 4 comments

Resolves #88

Should I also add an auth example via cookie?

I might need some help on the ok: false backward compatible thing

sandros94 avatar Jan 23 '25 02:01 sandros94

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Please upload report for BASE (main@9a8d499). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #112   +/-   ##
=======================================
  Coverage        ?   76.23%           
=======================================
  Files           ?        9           
  Lines           ?      711           
  Branches        ?      145           
=======================================
  Hits            ?      542           
  Misses          ?      167           
  Partials        ?        2           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jan 23 '25 02:01 codecov[bot]

Thanks @sandros94, this gave me some much needed guidance! However, I found that setting the context to an object doesn't work, you have to set specific properties. For example (using [email protected]):

Trying to set request.context to a new object:

upgrade(request) {
  request.context = { data: 'test'}
},
open(peer) {
  console.log(peer.context) // logs {}
}

Setting a specific property in request.context:

upgrade(request) {
  request.context.data = 'test'
},
open(peer) {
  console.log(peer.context) // logs { data: 'test' }
}

travis-r6s avatar Jan 29 '25 15:01 travis-r6s

@travis-r6s thanks for reporting it!

Indeed context is already initialized 😅

sandros94 avatar Jan 29 '25 16:01 sandros94

Good point @travis-r6s ~> https://github.com/unjs/crossws/issues/115

pi0 avatar Jan 29 '25 16:01 pi0