Skip to content

Commit

Permalink
fix: provider creation (#1514)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuizAsFight authored Sep 27, 2024
1 parent 2ae3105 commit 5f456f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
6 changes: 6 additions & 0 deletions .changeset/lucky-cows-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-wallet/connections": patch
"@fuels/playwright-utils": patch
---

Fix provider overriding url
30 changes: 1 addition & 29 deletions packages/connections/src/utils/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,6 @@ export const createProvider = async (url: string) => {
if (providers[url]) {
return providers[url];
}

// Regular expression to match the URL with basic auth credentials
const regex = /^(https?:\/\/)([^:@]+):([^:@]+)@(.*)$/;
const match = url.match(regex);

let username: string | undefined;
let password: string | undefined;
let urlNoBasicAuth = url;
if (match) {
// Extract username and password from the match
username = match[2];
password = match[3];
// Remove the username and password from the URL
urlNoBasicAuth = url.replace(`${match[2]}:${match[3]}@`, '');
}

// create provider with the URL without basic auth credentials
providers[url] = await Provider.create(urlNoBasicAuth, {
requestMiddleware: async (req) => {
if (req?.headers && username && password) {
// Add basic auth credentials to the request following browser way
const auth = `Basic ${btoa(`${username}:${password}`)}`;
// biome-ignore lint/complexity/useLiteralKeys: <explanation>
req.headers['Authorization'] = `${auth}`;
}
return req;
},
});

providers[url] = await Provider.create(url);
return providers[url];
};

0 comments on commit 5f456f1

Please sign in to comment.