om

Please ask the channel first, not @dnolen directly!
devo 2017-10-05T03:10:52.000035Z

How do folks generally auth and set cookies with om.next? Somewhat difficult for me to reason about since setting a cookie would be an effect that isn't captured in the state of the application.

levitanong 2017-10-05T08:13:22.000296Z

@devo re: auth do you mean JSON web tokens? if so, i just store those access tokens in my app state, then assoc those into the AST to be sent to the remote

levitanong 2017-10-05T08:14:46.000072Z

As for cookies: you could do it on app run, before om starts. Check the cookies. If the auth exists in your cookies, then store it in your app state e.g. (om/merge! reconciler {:app/session session})

levitanong 2017-10-05T08:15:16.000070Z

where session is whatever information you get from your cookie

levitanong 2017-10-05T08:16:09.000341Z

and if that info doesn’t exist, then route to your login page

levitanong 2017-10-05T08:16:38.000208Z

https://github.com/compassus/compassus

levitanong 2017-10-05T08:17:41.000170Z

alternatively, if you want to give some functionality to the user even if she isn’t logged in, you have a few options:

levitanong 2017-10-05T08:20:42.000024Z

can be used together or separately 1. have your components ask for your app session (which should be in your app state) to decide what to show 2. watch for 401 errors in your remote responses and then reroute to login

levitanong 2017-10-05T08:21:14.000181Z

you can also do some auth checks in your mutates, but checking for 401 is the most elegant for me.

levitanong 2017-10-05T08:22:08.000045Z

and since I do enterprise apps, i’ve not really done much of having my components for app session since my clients always want the user to be logged in anyway. But yeah, that’s something that’s open to you if you want to conditionally show things other than a log in screen

levitanong 2017-10-05T08:22:44.000432Z

further, if you have a complex web app, your server auth would probably give you back additional information like role or access permissions. those you can store also in your app state, and then accordingly use those in your components

devo 2017-10-05T08:26:03.000182Z

Is it best practice for login pages to be mostly static? Was making a login page w/ om just to get an idea of how to get SSR / remotes working as well as learn a bit about query params, i.e. serving a login / account creation page on 401's and using om to provide feedback on email / password validation.

devo 2017-10-05T08:27:30.000251Z

In the use case where I have om on this page, successful logins would yield a jwt from the server and I would then merge that into cookies and redirect to the originally requested url.

devo 2017-10-05T08:27:53.000038Z

and failures would be represented in the app state and provide user feedback

levitanong 2017-10-05T08:35:14.000081Z

@devo I make my login pages dynamic. they’re another om component.

levitanong 2017-10-05T08:37:30.000352Z

nothing against them being static, of course. you just lose out on inline validation

devo 2017-10-05T08:37:55.000435Z

Do you do full redirects between the login page and other pieces of the application, or is the login piece just a component that is routed to w/ compassus based on current state?

levitanong 2017-10-05T08:38:10.000197Z

the latter

levitanong 2017-10-05T08:38:34.000133Z

i also use pushy for pushstate so it looks like it’s a full redirect

devo 2017-10-05T08:38:43.000419Z

ok. That makes sense, cause then tokens could entirely be represented in the app state instead of needing to be stored for a full redirect.

levitanong 2017-10-05T08:38:49.000107Z

yes

levitanong 2017-10-05T08:39:15.000087Z

but i’d say as best enterprise practice, that you make it work even without javascript

levitanong 2017-10-05T08:39:34.000153Z

that would include the effort for full redirect

levitanong 2017-10-05T08:40:05.000193Z

i.e. your login page would work even before the javascript loads (in the case of a slow connection)

levitanong 2017-10-05T08:40:19.000261Z

but for most MVPs, you don’t need that

devo 2017-10-05T08:41:00.000009Z

Gave me a couple of things to think about for this. Thanks!

levitanong 2017-10-05T08:41:08.000060Z

np!