Skip to content

Commit 5089bef

Browse files
fix: replace URL object with string concatenation for React Native compatibility (#14516)
1 parent 4ff079c commit 5089bef

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

packages/auth/src/providers/cognito/apis/signInWithRedirect.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ const oauthSignIn = async ({
130130
params.append('code_challenge', toCodeChallenge());
131131
params.append('code_challenge_method', method);
132132
}
133-
const oAuthUrl = new URL('/oauth2/authorize', `https://${domain}/`);
134-
oAuthUrl.search = params.toString();
133+
134+
// Using URL object is not supported in React Native as the `search` property is read-only
135+
// See: https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Blob/URL.js
136+
const oAuthUrl = `https://${domain}/oauth2/authorize?${params.toString()}`;
135137

136138
// this will only take effect in the following scenarios:
137139
// 1. the user cancels the OAuth flow on web via back button, and
@@ -140,11 +142,8 @@ const oauthSignIn = async ({
140142

141143
// the following is effective only in react-native as openAuthSession resolves only in react-native
142144
const { type, error, url } =
143-
(await openAuthSession(
144-
oAuthUrl.href,
145-
redirectSignIn,
146-
preferPrivateSession,
147-
)) ?? {};
145+
(await openAuthSession(oAuthUrl, redirectSignIn, preferPrivateSession)) ??
146+
{};
148147

149148
try {
150149
if (type === 'error') {

0 commit comments

Comments
 (0)