-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(auth): improve query and error handling when completing sign in
- Add handling for when there is an empty hash - Add utility function to more easily handle query params AFFECTS PACKAGES: @esri/arcgis-rest-auth @esri/arcgis-rest-request
- Loading branch information
1 parent
85f73b2
commit 4b3905c
Showing
4 changed files
with
75 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/arcgis-rest-request/src/utils/decode-query-string.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* Copyright (c) 2017-2020 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
|
||
export function decodeParam(param: string): { key: string; value: string } { | ||
const [key, value] = param.split("="); | ||
return { key: decodeURIComponent(key), value: decodeURIComponent(value) }; | ||
} | ||
|
||
/** | ||
* Decodes the passed query string as an object. | ||
* | ||
* @param query A string to be decoded. | ||
* @returns A decoded query param object. | ||
*/ | ||
export function decodeQueryString(query: string): { [key: string]: string } { | ||
return query | ||
.replace(/^#/, "") | ||
.split("&") | ||
.reduce( | ||
(acc, entry) => { | ||
const { key, value } = decodeParam(entry); | ||
acc[key] = value; | ||
return acc; | ||
}, | ||
{} as any | ||
); | ||
} |