Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: provider creation #1514

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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];
};
Loading