Backend Workflow: Redirection on Success Not working

In my walkthrough, I’ve highlighted with :grinning:smiley emojis :grinning:, points which I do not understand why it does not work from a Bubble perspective.

The link to the development version: http://app.rewardnation.co/version-test/install?debug_mode=true

tldr:

  1. An Unhandled Error Occurs event doesn’t catch a workflow error, am I doing something wrong?
  2. Backend Workflow Page Redirect(302) Response Type does not redirect, why?
  3. Is there any way for the Backend Workflow to communicate with the Client on when it’s completed running or whether it’s successful?

Objective : I’m trying to build a manual OAuth with Slack because the BubbleSlack plugin doesn’t give me the scopes that I require.

Approach :

  1. There’re 2 API calls that are used, 1 to get the Access Token and the other to get the User’s Profile Information. Kudos to @ambroisedlg and his well written guide on OAuth

  2. The User goes to the Install page and clicks on the Slack Manual OAuth button, for clarity, I’ve labelled it

  3. This triggers the relevant Workflow, which directs them to the Slack_OAuth_Redirect page

  4. On the Slack_OAuth_Redirect page, 1 of the 2 Page Load Workflows will trigger: Page Load Slack Authorization

  5. After the User authorizes on Slack, they are redirected back to Slack_OAuth_Redirect and the other Workflow triggers: Page Load Slack Access Token

Page Load Slack Access Token is the Workflow that I’m having issues with. I would like to:

  1. Sign the User Up (And catch the edge case where an existing User tries to Sign Up)
  2. Log the User In
  3. Redirect back to the Install page

In the above screenshot that there are 2 other Workflows highlighted in Red. These are Test Slack Sign Up API and Test V2 Slack Sign Up API . They are alternative approaches that I’ve taken to try to solve my problem.

Privacy Rules for the User Type is shown in (Screenshot 6).

Problems:

Problem 1: Page Load Slack Access Token

This works and the User successfully Signs Up, Logs In, and gets redirected to the Install page. However, this does not handle the case scenario where an existing User tries to Sign Up through the same Workflow. This throws a Workflow error, as shown in below screenshot.

I’ve tried to solve this issue in 2 ways:

  • :grinning:Using An Unhandled Error Occurs event :grinning:. This somehow doesn’t work, even though it works fine for us on an email/password Sign Up page.

  • Using Only When in the Sign the User Up event. I understand this doesn’t work because of the Privacy Rules that exist, and since the Current User isn’t Logged In, is unable to conduct a search for Users.

Since the Page Load Slack Access Token didn’t work, I tried moving the Sign Up flow to a Backend Workflow instead.

Problem 2: Test Slack Sign Up API

According to the Server Logs, this works too. The User successfully Signs Up and Logs In. By clicking on Ignore Privacy Rules, the edge case of an existing User Signing Up is detected and bypassed to allow the existing User to Log In instead.

I detect the Log In event through a Console Log, where the Current User’s email is printed.



But the User does not get redirected and remains on the Slack_OAuth_Redirect page. I’ve tried to solve this issue in 2 ways:

  • :grinning:By configuring the Response Type of the Backend Workflow to be Page Redirect(302) :grinning:, as per my original screenshot.

This somehow doesn’t work as intended. From my understanding of this forum post by @emmanuel, once the Workflow completes, the redirect should trigger, regardless of success or failure and the User should thus be redirected to the respective success / failure pages. However in my application, the User remains on the Slack_OAuth_Redirect page.

  • By implementing several different ways of redirection upon User becoming Log In in the Slack_OAuth_Redirect page’s Workflows.

My hypothesis here is that the :grinning:User is Logged In on the Server side, but not on the Client side and the browser does not recognise that the User is Logged In :grinning:. The triggers therefore do not happen.

Could anyone confirm this?

Problem 3: Test V2 Slack Sign Up API

Acting on the second hypothesis from Problem 2, I tried implementing the Log In on the page’s Workflows instead, while keeping the Sign Up in the Backend to continue enabling validation. This approach isn’t very feasible due to the asynchronous nature of Backend Workflows, causing the Log In event to be triggered before the Sign Up is complete. I’ve tried to address this below:

  • Trying to get some form of a response from the Backend Workflow, and using that to limit ( Only when Result of Step 4 is “200” ) the Log In event from triggering. This however does not seem to work as :grinning:I’m unable to get the Backend Workflow to communicate with the Client :grinning:. Is there any way for the Backend Workflow to communicate with the Client on when it’s completed running or whether it’s successful?

Thanks for reading this far! Any other ways experienced Bubblers can think of to solve my use case?

First question: Will your user will already exist and you just want them to be able to add Slack and use slack from your App or you want the user to create an account in your app using Slack (and after use info to do something else with slack)?

The first blog post for oAuth manual is the way to go for the first case. API Connector oAuth2 process is the way to go for the second option (when this is possible).

In the first case, you shouldn’t care about the user exist or not, because he is already logged in. in the second case, Bubble will handle this part for you. So no worry about that too.

No, the User won’t already exist. The process is intended to:

  1. Install Slack App Bot into User’s Slack Workspace
  2. Sign the User up
  3. Log the User in

API Connector oAuth2 process does not work because Slack’s oAuth2 process involves 2 access tokens (Bot and User), and Bubble’s API Connector oAuth2 does not handle that properly (or maybe I just wasn’t able to get it configured properly).

Hence I went the manual oAuth way as specified in the @ambroisedlg’s post.

However, the issue I’m running to while implementing manual oAuth2 is in handling the edge case of an Existing User trying to Sign Up. I’ve tried 3 broad ways to solve this, but was unable to, hence the post to see if anyone has any ideas to contribute, or to highlight if I’m doing something wrong. :slight_smile:

You are right. Bubble will have issue with two access token and more, you will need to store bot Token to use according to what you want to do.
Two options:
Ask user to use Bubble login and after, they can connect their Slack account.
Authenticate them using Slack, but don’t really use the native Bubble login process and create your own.

I prefer the first option. In both case, the process for using Slack oAuth2 is the same and you will use the guide on oAuth like you did first. The only difference with the second option is that you need to create a user and check if user already exist or not after authenticate them using Bubble Do a Search condition to know if you need to create or update user.

@felix1 @Jici we have just launched a plugin for Slack OAuth that would handle this for you. Here is the link to the plugin page: https://bubble.io/plugin/slack-connector-1610513742546x296251631289499650

Note: you will need to install the UI element plugin by Pathfix first that works across all our plugins (it helps avoid javascript pileup)

hey felix! I am attempting to do something similar with slack - In initialization of the api call no matter what I do the response from slack has been “invalid_code” which seems odd. The page is redirecting properly and I am then able to authenticate and retrieve a code from the URL - but it seems as the though the code is invalid. Any thoughts on why this may be the case?

I know this is very late but I had this issue too. I put my solution here if it’s any use to anyone

This part is still an enigma to me :thinking: