Fork me on GitHub
#re-frame
<
2020-02-19
>
mh.meraji17:02:55

Hi I am recently working on a single page app that is implemented by re-frame my app has a login page and after the login is succeeded I redirect the client to the main page I also want to redirect the user to login page if the result of any request from server is error 403 I am using re-frame-http-fx library for effect handling on it's failure (`:on-failure`) I redirect them to the login page I want to know if this is the best practice for handling authorization failures? Thank you.

Lu18:02:06

If I may suggest, you don’t want to redirect the user to the login page in case of a 403. Instead, in that very same error handler I would assoc an error message to the re-frame state and display it beneath the login form through a subscription :)

andrea.crotti21:02:20

what's the best way to do some smart mobile/desktop behavior with re-frame? atm I have a helper function like

(defn mobile?
  []
  (< js/window.screen.availWidth 500))

andrea.crotti21:02:03

not very sophisticated surely, and then in the cljs code I have a few (if (mobile?) (do-this) (do-that))

andrea.crotti21:02:42

it kind of works but not exactly automatically when the resolution changes, I have to trigger some action or refresh the page

andrea.crotti21:02:00

any better ways to do this? Ideally I should be able to do something in CSS directly, but for example if I want to render entirely a different page (and I'm serving the same HTML server side) it's much easier to do it in CLJS

isak22:02:41

@andrea.crotti you can use a goog.dom.ViewportSizeMonitor, then dispatch an event in the callback that sets some state, then use a subscription

Lu22:02:49

Some ideas: • use CSS to set the display property of the root component of your desktop and mobile code. With media queries you can achieve the same CLJS mobile? functionality and it will also work when resizing, as you will swap display: block for display: none • If you really can’t stand this approach, add a js resize event listener that calls a re-frame handler .. basically what isak suggested

Lu22:02:51

The drawback of the CSS approach is that the DOM will be polluted with elements that aren’t all actually there .. but you’re definitely gaining on simplicity and performance too

4