Fork me on GitHub

@tony.kay what is the right place to trigger a query on app load to fetch the current user, and then on reception of the resutl of that query transition the state of a top-level ui state machine?


Here’s what I’d do: Make a top-level state machine, and begin! it on started callback. That state machine would issue the remote read with events for success/failure…it would probably be a state machine that I leave running, and is responsible for the “login”


@tony.kay ah I see, and where would the remote read be issued?


in the state machine


it supports loads with events as post processing


:post-event etc


@tony.kay Ok, thanks. Two additional questions: in the lein fulcro template, how can I , before every mutation/query except a select few (i.e. the authenticate mutation), load up a user from a session id and make it accessible to mutations/queries. If the user session id is invalid, return some error code (i.e. http 401) and on the frontend, if any request fails with a 401 clear the db and redirect to the login page?


I can't write your entire login and session mgmt for you :)


@tony.kay you are right; sorry for the bother


I don’t mind specific questions 🙂 That is a bit much, though. The session stuff is Ring (e.g. ring-session)…so read the docs there. The book tells you how to get things into the env of the parser (and the template has comments pointing out the spots)…the template, I think, puts the request in the env, which would have the session. I’d use a login state machine, like is in the docs for ui state machines in incubator.


From there, you’ll need to piece it together. Perhaps if I get some time I’ll write a new example project that has some of these basics prewritten.


putting something in front of every mutation/read could be done with a wrapper on defmutation/resolver…which the new template gives you, and having the request (which has session) in the env lets you check whatever you want.


Summary: 1. Put ring request in env (see comments in template for where to do that…look for handle-api-request, I think) 2. Add ring-session configuration to Ring (see ring-defaults docs if using the template, since it includes it). 3. On login, stick stuff in session (see augment-response in Fulcro, or use the session store in Ring directly (easier)). 4. In macros that wrap defmutation and defresolver: add logic, OR add logic to each mutation/resolver that needs security. The pathom parser plugins could be used to do things like query for real database things BASED on session and put them in env, or you could enforce security there.


(and/or redirect)


@tony.kay how do you run your fulcro server so that code changes ( server side ) are refreshed automatically ? we using datomic and mount, but i am not getting the refresh behaviour for some reason when I run the main function in this file


I don’t have an automatic refresh…I just type (restart) in the REPL….you can map a hot key in IntelliJ to run that.


this is assuming you’re using the template, which has the refresh directories set correctly as well.


ok .. i try that .. thanks


what do you mean by template?


The lein template


@tony.kay Hi! Are you around? I just read through the doc on state machines twice but I’ve a couple of questions


Unrelated: is there a way to know if some data related to a component is laoding? for example when transitioning to an “exercise” page I don’t want to show a globla loading indicator, but only a loading indicator in a specific area of the screen


(so :ui/loading-data isn’t suitable it seems)


ah nevermind, found the explanation in the book!


(if (and loading-data (empty? items))


Also check out the flicker-free marker helpers in incubator.


@hmaurer look for load markers in the book


@wilkerlucio yup got it 🙂 thanks