Skip to content

Commit f8a2671

Browse files
committed
use queryString helper in auth-next (#2936)
* Use queryString from firebase/util instead of homebrew one * [AUTOMATED]: Prettier Code Styling * PR Feedback * [AUTOMATED]: Prettier Code Styling
1 parent 24bf1ec commit f8a2671

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

packages-exp/auth-exp/src/api/index.ts

+8-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { FirebaseError } from '@firebase/util';
18+
import { FirebaseError, querystring } from '@firebase/util';
1919
import { AuthErrorCode, AUTH_ERROR_FACTORY } from '../core/errors';
2020
import { Auth } from '../model/auth';
2121
import { IdTokenResponse } from '../model/id_token';
@@ -65,28 +65,25 @@ export async function performApiRequest<T, V>(
6565
const errorMap = { ...SERVER_ERROR_MAP, ...customErrorMap };
6666
try {
6767
let body = {};
68-
const params: { [key: string]: string } = {
69-
key: auth.config.apiKey
70-
};
68+
let params = {};
7169
if (request) {
7270
if (method === HttpMethod.GET) {
73-
Object.assign(params, request);
71+
params = request;
7472
} else {
7573
body = {
7674
body: JSON.stringify(request)
7775
};
7876
}
7977
}
8078

81-
const queryString = Object.keys(params)
82-
.map(key => {
83-
return `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`;
84-
})
85-
.join('&');
79+
const query = querystring({
80+
key: auth.config.apiKey,
81+
...params
82+
}).slice(1);
8683

8784
const response: Response = await Promise.race<Promise<Response>>([
8885
fetch(
89-
`${auth.config.apiScheme}://${auth.config.apiHost}${path}?${queryString}`,
86+
`${auth.config.apiScheme}://${auth.config.apiHost}${path}?${query}`,
9087
{
9188
method,
9289
headers: {

0 commit comments

Comments
 (0)