aboutsummaryrefslogtreecommitdiffstats
path: root/src/api
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2021-02-13 01:13:37 +0300
committerGravatar Hassan Abouelela <[email protected]>2021-02-13 01:18:22 +0300
commit2350aa12fae661e37895616e0e7fe3e7ebc62f53 (patch)
treeb7ff0b51096f6f5e0a34ac7a0feb5f9e2e880f9d /src/api
parentCleans Up OAuth Button (diff)
Makes Authorize Helper Async
Signed-off-by: Hassan Abouelela <[email protected]>
Diffstat (limited to 'src/api')
-rw-r--r--src/api/auth.ts8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/api/auth.ts b/src/api/auth.ts
index ae20236..fa3ac85 100644
--- a/src/api/auth.ts
+++ b/src/api/auth.ts
@@ -190,19 +190,21 @@ export async function requestBackendJWT(code: string): Promise<JWTResponse> {
* @param disableFunction An optional function that can disable a component while processing.
* @param path The site path to save the token under.
*/
-export default function authorize(scopes?: OAuthScopes[], disableFunction?: (newState: boolean) => void, path = "/"): void {
+export default async function authorize(scopes?: OAuthScopes[], disableFunction?: (newState: boolean) => void, path = "/"): Promise<void> {
if (!checkScopes(scopes, path)) {
const cookies = new Cookies;
cookies.remove(CookieNames.Token + path);
cookies.remove(CookieNames.Scopes + path);
- getDiscordCode(scopes || [], disableFunction).then(discord_response =>{
- requestBackendJWT(discord_response.code).then(backend_response => {
+ await getDiscordCode(scopes || [], disableFunction).then(async discord_response =>{
+ await requestBackendJWT(discord_response.code).then(backend_response => {
const options: CookieSetOptions = {sameSite: "strict", expires: backend_response.Expiry, secure: PRODUCTION, path: path};
cookies.set(CookieNames.Token + path, backend_response.JWT, options);
cookies.set(CookieNames.Scopes + path, discord_response.cleanedScopes, options);
});
});
+
+ return new Promise<void>(resolve => resolve());
}
}