This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-19
Channels
- # announcements (1)
- # architecture (24)
- # beginners (7)
- # boot (7)
- # cider (1)
- # cljdoc (4)
- # clojure (20)
- # clojure-austin (1)
- # clojure-brasil (2)
- # clojure-dev (1)
- # clojure-italy (1)
- # clojure-spec (36)
- # clojure-uk (11)
- # clojurescript (44)
- # data-science (3)
- # datascript (1)
- # datomic (8)
- # figwheel-main (2)
- # fulcro (29)
- # graphql (9)
- # kaocha (2)
- # keyboards (1)
- # leiningen (3)
- # lumo (5)
- # nrepl (4)
- # off-topic (39)
- # onyx (5)
- # re-frame (2)
- # shadow-cljs (42)
- # tools-deps (18)
- # yada (65)
@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 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 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.
@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?
gotcha
@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
@hmaurer look for load markers in the book
@wilkerlucio yup got it 🙂 thanks