Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
06e6bd1a
Commit
06e6bd1a
authored
Apr 20, 2021
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract `exchangeAuthCodeForToken` method
Extract a helper from a long async method to shorten it.
parent
edb9c257
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
10 deletions
+15
-10
auth.js
src/sidebar/services/auth.js
+15
-10
No files found.
src/sidebar/services/auth.js
View file @
06e6bd1a
...
...
@@ -161,6 +161,20 @@ export class AuthService extends TinyEmitter {
return
tokenInfo
;
};
/**
* Exchange authorization code retrieved from login popup for a new
* access token.
*/
const
exchangeAuthCodeForToken
=
async
()
=>
{
const
code
=
/** @type {string} */
(
authCode
);
authCode
=
null
;
// Auth codes can only be used once.
const
client
=
await
oauthClient
();
const
tokenInfo
=
await
client
.
exchangeAuthCode
(
code
);
saveToken
(
tokenInfo
);
return
tokenInfo
;
};
/**
* Retrieve an access token for the API.
*
...
...
@@ -189,16 +203,7 @@ export class AuthService extends TinyEmitter {
tokenInfoPromise
=
Promise
.
resolve
(
null
);
}
}
else
if
(
authCode
)
{
// Exchange authorization code retrieved from login popup for a new
// access token.
const
code
=
authCode
;
authCode
=
null
;
// Auth codes can only be used once.
tokenInfoPromise
=
oauthClient
()
.
then
(
client
=>
client
.
exchangeAuthCode
(
code
))
.
then
(
tokenInfo
=>
{
saveToken
(
tokenInfo
);
return
tokenInfo
;
});
tokenInfoPromise
=
exchangeAuthCodeForToken
();
}
else
{
// Attempt to load the tokens from the previous session.
tokenInfoPromise
=
Promise
.
resolve
(
loadToken
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment