Skip to content

Commit

Permalink
fix: handle jwt messages correctly in daf-url in browser environments
Browse files Browse the repository at this point in the history
I was sending through a message with a JWT in the raw and my agent running in the browser has in the MessageHandler chain `daf-url` active. 

I ran into errors because `const parsed = parse(message.raw, true)` returned an URL object with the URL of the page. The URL came out as http://localhost:3000/jwthere. Which of course did not resolve to something dad could understand.

After some digging, I found the following in the `url-parse` documentation

> Note that when `url-parse` is used in a browser environment, it will default to
using the browser's current window location as the base URL when parsing all
inputs. To parse an input independently of the browser's current URL (e.g. for
functionality parity with the library in a Node environment), pass an empty
location object as the second parameter. (https://github.com/unshiftio/url-parse/pull/65/files)

This commit adds the {} parameter.
  • Loading branch information
roderik authored May 28, 2020
1 parent d82de54 commit db26132
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/daf-url/src/message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const debug = Debug('daf:url:message-handler')

export class UrlMessageHandler extends AbstractMessageHandler {
async handle(message: Message, agent: Agent): Promise<Message> {
const parsed = parse(message.raw, true)
const parsed = parse(message.raw, {}, true)

if (parsed && parsed.query && parsed.query.c_i) {
debug('Detected standard URL')
Expand Down

0 comments on commit db26132

Please sign in to comment.