From ba8f8d92ec1b453d2740c7220b18eb1d617a982f Mon Sep 17 00:00:00 2001 From: puneet222 Date: Sat, 27 Mar 2021 12:12:23 +0530 Subject: [PATCH] Handle user logout scenario --- src/actions/setup.ts | 47 ++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/src/actions/setup.ts b/src/actions/setup.ts index 47e758b..f10d9d8 100644 --- a/src/actions/setup.ts +++ b/src/actions/setup.ts @@ -1,28 +1,37 @@ // @description Setup the asana automation package open("https://app.asana.com/0/developer-console"); -click('New access token'); -const tokenName: string = `workerb-${new Date().getTime()}`; +const currentURL = readURL(); -type(tokenName, 'What will this token be used for?', { method: 'by_placeholder' }); +if(currentURL.indexOf("login") === -1) { + // user already logged in + click('New access token'); -//@ts-ignore -click('I agree to the API terms and conditions', { method: 'by_label' }); -click('Create token'); + const tokenName: string = `workerb-${new Date().getTime()}`; -const token = read('.CopyTextbox-text', { method: 'by_query_selector' }); + type(tokenName, 'What will this token be used for?', { method: 'by_placeholder' }); -notify(token, "success", 3000); + //@ts-ignore + click('I agree to the API terms and conditions', { method: 'by_label' }); + click('Create token'); -if (!token) { - notify("Empty token", "error", 3000) + const token = read('.CopyTextbox-text', { method: 'by_query_selector' }); + + notify(token, "success", 3000); + + if (!token) { + notify("Empty token", "error", 3000) + } else { + setVars([ + { + name: 'asanaAccessToken', + value: token, + }, + ], { local: true }); + notify('Access token added successfully', 'success', 4000); + reIndex([]); + } } else { - setVars([ - { - name: 'asanaAccessToken', - value: token, - }, - ], { local: true }); - notify('Access token added successfully', 'success', 3000); - reIndex([]); -} + // notify user not logged in + notify("Please login into your Asana account", "error", 3000); +} \ No newline at end of file