Fork me on GitHub
#luminus
<
2020-04-20
>
jtth20:04:39

after login i’m redirecting to another page using the following, but it doesn’t seem to preserve session information. any ideas on where i should look?

(-> (response/found "/authenticated-test")
        (assoc :session (assoc session :identity user-identity)))
there isn’t even a :session value in :params. (I asked this in #ring too.)

jtth21:04:56

Like, is it due to something having to do with buddy’s session and this? https://github.com/metosin/reitit/issues/205

jtth16:04:07

This is the repo https://bitbucket.org/jtth/irbportal/src/bb8382ddc933842023f8bfba4353a5dcd7a5ace1/src/clj/irbportal/routes/auth.clj#lines-49. Any help is much appreciated. Otherwise I’m gonna have to just build all this up from scratch without luminus and reitit blocking my understanding, and if I can’t get that to work I’m going back to rails and devise.

shayne.koestler16:04:58

I recently just added the same thing to my luminus project, in your snippet I see there's a session variable, where is that coming from? For what its worth heres the snippet I have

(-> (response/ok {:username email})
           (assoc :session {:username email}))

jtth17:04:00

how does that deal with redirection then? this is what i’m not getting

shayne.koestler17:04:31

I'm not actually going to redirect. Are you able to see if the session identity is properly set on requests after the redirect?

jtth17:04:18

that is what this question is about

jtth17:04:34

and how are you having someone log in without redirecting them after the POST to the login route

shayne.koestler17:04:49

I'm doing a re-frame front end so I'm just setting some state on the front end when I get a 200

jtth17:04:58

Ok well that’s not very helpful

jtth17:04:04

this isn’t an SPA

jtth17:04:37

I figured it out. The session is fine, there’s just no way of accessing it within luminus’s layouts. Which… what is the point of the template if not to provide such things?.

shayne.koestler17:04:24

If you go to layout.clj you can update render to pass it in

shayne.koestler17:04:27

I am actually doing that

shayne.koestler17:04:43

(defn render
  "renders the HTML template located relative to resources/html"
  [request template & [params]]
  (content-type
    (ok
      (parser/render-file
        template
        (assoc params
          :page       template
          :csrf-token *anti-forgery-token*
          :username   (get-in request [:session :identity]))))
    "text/html; charset=utf-8"))

jtth17:04:56

Yeah, got that. Not sure why the session info isn’t just… there for each template to get… because… what is the point of the template if it can’t?

jtth17:04:10

Like, is there a reason I shouldn’t just pass :session into each template?

shayne.koestler17:04:07

Only reason I can think of is there might be secure info in there and if the whole object is passed to the template its easier to accidentally serialize it into the response. That's the only reason I could think of