Change Page in Workflow with Path from DB

I am using Magic Link to login a user.

The DB response includes an authToken and a Target URL that the user should then be taken to.

The target URL will always change, and will include query string parameters. So, it may be something like /dashboard/property?property-id=35 or /dashboard/offer?offer-id=104&action=add

I tried using the Change Page Action, but I don’t think it will work because I cannot provide an array of query string variables. Only one variable with a set key.

I tried using the following JS, but it does not work… it produces a 404 error (this may have something to do with my DNS settings not being correct for naked URLS?)

window.location.pathname = 
context.workflow['7db9 ... 0dd2'].result['data']['target_url'];

How can I use a workflow action to send the user to a page in my site that includes query string variables?

Note: I’ve also tried to just use the page id from WeWeb, but then I cant get the query string variables in there.

I have control over the target_url field, so I can set this up however needed to make this work.

1 Like

I was fiddling a bit with wwLib. It looks like you can do wwLib.goTo('you rpage uuid', {your_query_name:'your query value'}).

2 Likes

That’s brilliant! I’ll try it shortly. Thank you!

We should definitly one day publish all wwLib function we want to expose :).

Be aware that wwLib functions may change later if we have not mark them as “public”.

Maybe we can start a subject with all of what you use (and so need), so we know what should be marked as public.

5 Likes

@aurelie Outside of some form validation JS, Here are the three things that I’m often using which are more custom:

  1. Changing page with multiple query items like mentioned above. This could be simply solved by allowing a bindable array with key/value query string parameters in the Change Page action.
wwLib.goTo('you rpage uuid', {your_query_name:'your query value'}).
  1. Changing page to an outside URL in a workflow action. There is the ability to go to an outside URL with a link, but not an action … I’ve been using this with Stripe Checkout:
location.href = https://wwww.checkout.stripe/foo-bar
  1. Login a user with an authToken … When using MagicLinks, the front end receives back an authToken. We then need to log that user in on the front end. There is no way to do this right now with the auth plugins … I’ve been doing this with 2 actions:

a) Setting the WeWeb accessToken (plugins.Xano.accessToken)

variables[/* xanoAuth accessToken */ 'f5856798- ... c64e1-accessToken'] = context.workflow['896cc5e6-9f06- ... 4f2b9'].result['data']['auth_token']

b) Then fetching the user with a regular Fetch User action

(Note: I’m actually not sure if the Login with Auth Token workflow is working right now. I was receiving an error but might not be related to above)

3 Likes

@kevinwasie I am currently trying to call an outside URL in a workflow, similar to the Stripe Checkout you mentioned. Used your example of the location.href, but it looks like the new URL is not opening on a blank page but is loaded into a frame or something. This is blocked by the external Service I am calling. Do you know a possibility to open an external URL in a workflow on a blank page?

  1. JS for external URL in workflow

  2. Resulting error page

@Soenke Does this happen when you publish your app also?

I think that is expected behavior for the editor, as WeWeb editor will not load external pages, but I think that should work in the published version.

Try publishing and let me know.

Still on the free plan :grimacing: so I cannot test it unfortunately

Currently I try to figure out if it makes sense to move my application from bubble to WeWeb, so I rebuild and test the most important parts of my app in WeWeb before entering the paid plan.

1 Like

Got it. Okay… What you have there should work when you publish, and if something is wrong in the code, there will be a simple fix for it. Just cant load external pages in the editor.

Okay, sounds good.

Testing actions that need redirect is not with the best dx in weweb.

If you need a redirect outside your weweb app try window.top.location.href = "your url here".
It will load the url in the topmost window so in the editor you will leave it and load the page.

If you need a return url (eg. stripe checkout) you need to dynamically build the url: if context.browser['environment'] == "editor" use https://editor.weweb.io/your app id/your page id otherwise create it with your published domain.

1 Like

Because the editor load your app inside an iframe, be carefull with “window” inside editor :).
Normally you have a change page action which can help me and handle all these corner cases.

1 Like

Change page action works only for pages of the weweb app right?

If I need to redirect to an external site and test the flow of actions (eg. stripe checkout, I want to test a full purchase flow including redirect to checkout and back to the editor) I need to change the location of the top window with something like window.top.location.href = "your url here".

A variable in context.browser with both the base editor url and the live app url will be helpful to set the redirects back to the app. Right now I am setting them by hand.

2 Likes

Hmm yes indeed Change Page is for now only for internal webpage.
I am sending to the product team your suggestions: Change Page action should be able to redirect to external + expose the base url on variable.

5 Likes

Yes! @aurelie And possibly the ability to bind array keys and values to the querystring variables. I think this will be a common request internally and externally.

2 Likes

This is exactly what I am currently looking for in this post I recently posted. I checked the product roadmap and don’t see anything about this feature. Do you know if this is being worked on?

Hello, with the change page you can bind an external page

2 Likes

I get an error when I bind to an external page:

“Error: Page not found. at Aa (https://editor-cdn.weweb.io/public/js/index.931913bb.js:2583:123462) at Proxy.runTest (https://editor-cdn.weweb.io/public/js/index.931913bb.js:2583:339903) at https://editor-cdn.weweb.io/public/js/index.931913bb.js:2583:324841 at https://editor-cdn.weweb.io/public/js/chunk-vendors.30212033.js:165:88766 at Zi (https://editor-cdn.weweb.io/public/js/chunk-vendors.30212033.js:165:67544) at eo (https://editor-cdn.weweb.io/public/js/chunk-vendors.30212033.js:165:67635) at HTMLButtonElement.n (https://editor-cdn.weweb.io/public/js/chunk-vendors.30212033.js:165:76188) at HTMLButtonElement.sentryWrapped (https://browser.sentry-cdn.com/5.12.1/bundle.min.js:2:44863)”

Thanks, I figured out that the social logins for xano should resolve my issue. So I may just wait for that update.

@Mael I’m getting the same error as this.

1 Like