Fork me on GitHub
#fulcro
<
2020-05-28
>
zilti11:05:21

I'm a bit stuck on fulcro-rad-demo again. How is it determined if a route can be accessed with or without authentication? It seems form/defsc-form forms are by default only for logged in users? And how do I check for roles, or is that something that is not part of fulcro-rad's auth?

pvillegas1213:05:15

Auth is not fleshed out yet

zilti13:05:22

I understand that, but how is it working or supposed to work?

tony.kay13:05:05

in the demo: it’s barely working…don’t expect it to be “right”.

tony.kay13:05:21

at the moment making any kind of auth decision is still mainly your task.

tony.kay13:05:51

Now in terms of how it is supposed to work: well, I can give you some basics: 1. Say you want to go to Report A, which queries for attributes x, y, and z. 2. The system should scan x, y, and z (the attribute definitions, which would contain auth lambdas or something) and ask the auth machine: “Does it make sense to allow this, and if not, can you ask the user for creds to make it ok?” 3. The auth machine would go about its work (full-stack, async, possibly with auth redirects that require saving state in brower local state), and eventually sends an event back to the router (or report SM…not sure): Yes or No.

tony.kay13:05:53

so the basic idea is still attribute-centric, possibly with additional keys you could put on target component, that interacts with a pluggable auth state machine to both acquire authorization and authentication in order to see if a route “is legal at this time”

tony.kay13:05:11

That same plugin would likely be responsible for UI interactions.

tony.kay13:05:41

There’s also the problem of partial approval: the route is “ok”, but some of the attributes will need to be hidden or read only…

tony.kay13:05:14

So, its a large task. Consider the auth in the demo to be a very very bare bones starting point, and not remotely close to the real solution.

tony.kay13:05:24

And that real solution is currently beyond my real personal needs. I’m using the reports and forms to good effect in production. I don’t need the auth system.

tony.kay13:05:05

and many apps can do with just a “block unless auth’d” approach like in the demo, with just a bit of code wrapping the routing for auth redirect.

tony.kay13:05:17

So, short answer: Write your own landing page. Write your own auth. Record the target URL on start (where they wanted to go, and start RAD after they are logged in (at which point you can also update the URL to trigger a bookmark nav).

Eric Ihli16:05:35

I'm getting a "FORM NOT NORMALIZED" error when trying to perform a transact! and I'm struggling to understand why. My form has an ident.

(defsc UserForm [this {,,,}]
  {,,, :ident [::form ::user/id] ,,,}
The error prints out the form-config-path as core.cljs:159 ERROR [com.fulcrologic.fulcro.algorithms.form-state:506] - FORM NOT NORMALIZED: [:com.scratchoff-odds.ui/form #uuid "8e7bc28b-bad7-4f74-bb74-9317fab270cb"] My understanding is that it is normalized. That is a tuple of a table and id that uniquely identifies the form in the app state.
(get-in (app/current-state s.app/app)
           [:com.scratchoff-odds.ui/form #uuid "8e7bc28b-bad7-4f74-bb74-9317fab270cb"])
;; => {:ui/errors {},
;;     :com.scratchoff-odds.model.user/id
;;     #uuid "8e7bc28b-bad7-4f74-bb74-9317fab270cb",
;;     :com.scratchoff-odds.model.user/email "aset",
;;     :com.scratchoff-odds.model.user/password "",
;;     :com.fulcrologic.fulcro.algorithms.form-state/config
;;     {:com.fulcrologic.fulcro.algorithms.form-state/complete?
;;      #{:com.scratchoff-odds.model.user/email}}}
But mark-complete* conjs that tuple with ::config and checks eql/ident? on that config, which doesn't look like it will ever be an ident.
(>defn mark-complete*
  ",,,"
  (,,,
   (let [form-config-path (conj entity-ident ::config)
         form-config-path (if (eql/ident? (get-in state-map form-config-path))
                            (get-in state-map form-config-path)
                            (do
                              (js/console.log form-config-path)
                              (log/error (str "FORM NOT NORMALIZED: " entity-ident))
                              form-config-path))

cjmurphy17:05:50

Do you not want to do the lambda style for that ident i.e. a function?

Eric Ihli17:05:43

Ok. I have a thread to pull on. http://book.fulcrologic.com/#NetworkInteractionsandForms Looking at the database in fulcro inspector for that example I see that the ::config is different than mine. The value at form-config-path for me is a map while the value at form-config-path in that example is an ident. Both my code and that example have similar-looking queries. [::some-attr ,,, fs/form-config-join]. But that example has an ident that matches the "model". The example uses :person/id as an ident. I'm using an ident that's different from my "user" model table. I'm using [::form ::user/id] rather than ::user/id (or equilvalently [::user/id ::user/id]. I also see the example calls fs/add-form-config* inside the mutation that initializes an "empty" new person object. I'll need to look into what that does.

(defmutation edit-new-person [_]
  (action [{:keys [state]}]
    (let [person-id    (tempid/tempid)
          person-ident [:person/id person-id]
          phone-id     (tempid/tempid)]
      (swap! state
        (fn [s] (-> s
                  (add-person* person-id "" 0)
                  (add-phone* phone-id person-id :home "")
                  (assoc :root/person person-ident)         ; join it into the UI as the person to edit
                  (fs/add-form-config* PersonForm [:person/id person-id])))))))

Eric Ihli17:05:32

@U0D5RN0S1 Ah. Sorry. Yes. Same result though. The path to form-config-path still points to a value that is a map, not an ident.

dvingo19:05:44

do you have the initial state of the form in the component?

dvingo19:05:13

when i've seen this in the past it was either not adding the form config or not joining the component properly:

Make sure you have joined your form to the parent component.

{:query [:my-thing/form]}
;; should be
{:query [{:my-thing/form (comp/get-query MyForm)}]}

folcon22:05:16

I’ve got the same issue =)… Will look over your code later and see if we have any similarities…

murtaza5217:05:46

When I run shadow-cljs on the rad-demo project, and navigate to localhost:8081 the page that is server gives a console error main.js not found. There is no compilation error on the shadow-cljs console, so why is the js file not being served ?

tony.kay17:05:27

that’s shadow’s server I think…port 3000 if I recall right

tony.kay17:05:39

you did start the RAD app on CLJ REPL, right?

murtaza5217:05:41

oh I did not start it from the clj repl, I just started the shadow-cljs watch main, but then also it should have compiled and served the main.js, only the server part would not work, but the client part should have been served.

murtaza5217:05:50

let me try from the clj repl though

tony.kay17:05:04

The http from shadow is just serving from test folder I think

murtaza5217:05:13

aah got you the resource folder is not in path ...