Fork me on GitHub
Joe Lane18:02:03

Hi friends, I’ve got 2 questions. 1. If I was going to make use of the aws js cognito sdk, would I write a custom remote for it? I dont think I want the cognito io to happen in a mutation action, which is what led me to the remote. I’ll be doing the same thing today for s3, thus the same question applies for the aws js s3 sdk. 2. I worked through the localstorage abstraction blog post and got that working, but I now see those api’s are deprecated. What is the appropriate mechanism to implement something like the localstorage remote in 2019?


You can always speak with other aws services from your api remote directly, why do you want the UI to talk to them directly?

Joe Lane19:02:54

I dont want the ui to talk to them, I’m performing user signup.

Joe Lane19:02:13

And I’m trying to determine where the call to cognito should go once I gather the username and pass.

Joe Lane19:02:50

@U6Y72LQ4A when you say “from your api remote directly” what exactly do you mean?


You issue a mutation to your api remote, and the api remote (your backend), will call the various aws apis accordingly

Joe Lane19:02:13

Ok, great so the remote is the right place basically for io side effects to the outside world, like auth, file upload, etc.


Another suggestion - use the Amplify SDK (which includes Cognito). It includes an HOC for React that wraps your main UI, and handles all the authentication and user signup for you. It also has other components for S3 and other services that are really helpful. I’m using it in my app (which is React Native, but they have components for plain React as well) and it works pretty well. I let it handle all the dirty work, and then it fires events for when a user has signed in, signed up, etc. I handle those and fire a mutation that sets the user info in app state, then let Fulcro take over for everything else. One potential issue with the remote mutation approach and doing auth on the server - what if you want to use Cognito to secure your backend API as well? Maybe not an issue for you, but in my case the backend is a Datomic Ion exposed through Amazon API gateway, which can be configured to restrict access to authenticated members of a Cognito pool - a very nice extra layer of security IMO. Amplify also has an API service that will sign requests based on the Cognito user that’s logged in, so you can get this automatically (just need to write some middleware for the Fulcro networking layer, which I haven’t done yet but looks to be pretty straightforward). But if you authenticate on the backend, you lose that capability. Just something to consider. If you are interested in that approach, I can pull out some code snippets to share (for React Native, but conceptually it should work the same with React web).


is it typical for global state to default back to initial state on route changes?


I have a multi-step form I’m trying to setup - when I proceed to the next step, with route change, and go back, the values I changed aren’t persisting and going back to initial-state


@njj how are you handling the routing?


I’m using secretary, then to change a route I use the (secretary/dispatch! route) method


could you gist the relevant code? unless I am missing something this should not re-initialise the globla state (unless the whole page reloads). Fulcro doesn’t do anything automatically when the URL changes


Are you using a form element that is “submitting” to the server? I never use the DOM form element, since it has that “default” behavior, which of course will reload the whole app.


@U0CKQ19AQ No, right now I’m just changing routes with a “Continue” button. I can share a gist in a bit.


nothing about Fulcro will reinitialize your app


Everything is just a prototype/test of the forms stuff. This is the first I’ve used the newer fulcro forms


So, separate routing from forms. Get the forms working first, then add routing…and I’d suggest using the new dynamic router in incubator when you do


Forms are working


Or at least from what I can tell, its just when I go back and forth between routes that it loses its values and goes back to the initial state


I’m using dirac and can see the global values being updated when I type new values into the fields. Not sure if that helps or not.


Got me. I can’t see how this could be a Fulcro issue. If your state is resetting that only happens if you ask for it to happen (e.g. via a state reset), or reload the page…which secretary could cause if you haven’t set up history event handling correctly. Those are my guesses.


@njj how/where is your application started?


(def the-app (atom nil))

(defn new-untangled-client [& args]
  (reset! the-app (apply uc/new-fulcro-client args)))


@U0CKQ19AQ so I’ve confirmed my app-state is indeed staying in tact after changing routes, so it must be something weird with how I implemented this form. It just seems to be looking for the initial-state values over what I’ve added to the query?