Fork me on GitHub
#fulcro
<
2019-01-19
>
hmaurer17:01:22

@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?

tony.kay18:01:33

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”

hmaurer18:01:48

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

tony.kay18:01:09

in the state machine

tony.kay18:01:19

it supports loads with events as post processing

tony.kay18:01:23

:post-event etc

hmaurer22:01:48

@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?

tony.kay00:01:40

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

hmaurer02:01:21

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

tony.kay18:01:29

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.

tony.kay18:01:28

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.

tony.kay18:01:20

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.

tony.kay18:01:59

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.

hmaurer17:01:36

(and/or redirect)

daniel.spaniel17:01:01

@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

tony.kay18:01:35

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.

tony.kay18:01:58

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

daniel.spaniel19:01:16

ok .. i try that .. thanks

daniel.spaniel19:01:44

what do you mean by template?

tony.kay19:01:24

The lein template

hmaurer21:01:39

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

hmaurer23:01:35

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

hmaurer23:01:43

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

hmaurer23:01:42

ah nevermind, found the explanation in the book!

hmaurer23:01:50

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

tony.kay18:01:28

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

wilkerlucio23:01:48

@hmaurer look for load markers in the book

hmaurer23:01:48

@wilkerlucio yup got it 🙂 thanks