Fork me on GitHub
#cljsrn
<
2017-06-01
>
pesterhazy08:06:11

@aj, cookies are handled transparently by react-native, i.e. they are stored in a per-app cookie jar

pesterhazy08:06:11

they persist across app restarts, so as long as you use the regular JavaScript network request libs (js/fetch), you don't need to do anything

carocad08:06:51

@pesterhazy by any chance do you have an example?

carocad08:06:24

no, I already use fetch. In my case I call fetch on app start to get the tokens. Since that process always takes a while my guest was that nothing was being persisted. But you said that they are persisted transparently so if I call fetch with the same address as before, does it uses the known answer? i am a bit confuse sorry

pesterhazy08:06:03

it works just like on the web - RN acts like a web browser

wojciech08:06:06

> In my case I call fetch on app start to get the tokens I'm not sure if I got your authentication scenario right, but… If you get auth tokens back in the server response, then you have to manually save them (for example with AsyncStorage) on the devise and manually add them as headers to sub-sequent fetch calls. What @pesterhazy is talking about with automatic save is just cookies and will work if you have cookie-based authentication (not token-based).

pesterhazy08:06:34

ah you mean a token as in JWT?

carocad08:06:41

yes exactly

carocad08:06:56

@wojciech thanks a lot. That solved my confusion

pesterhazy08:06:38

yeah you'll have to set headers and store tokens manually then

pesterhazy08:06:03

(What's wrong with cookies? Why do people keep reinventing them?)

wojciech08:06:53

> What's wrong with cookies? Why do people keep reinventing them? I keep asking myself that… No idea 😞

carocad09:06:59

@pesterhazy well in the case of jwt they are self-signed. So there is no need to store the token safely. Any storage will work since the server can verify it. They are also stateless so no need to keep track of current sessions on both client and servers

pesterhazy09:06:35

can't you do that with cookie too? E.g. ring.middleware.session.cookie/cookie-store https://github.com/ring-clojure/ring/wiki/Sessions#session-stores

carocad09:06:28

not sure if I understand that right, but that means that you still need to store the cookie in the server right?

carocad09:06:40

I am actually not very qualified to explain the whole thing since I am still learning about it but I think this blog post can explain it better https://auth0.com/blog/cookies-vs-tokens-definitive-guide/

pesterhazy09:06:00

no, an encrypted cookie can be client-side only (that's a best practice too)

pesterhazy09:06:43

if you have a choice in the matter, consider not buying into the JWT hype, it may not be worth it for your use case

carocad09:06:06

well I dont really have a choice for this. I am using external authentication services g+ facebook, etc

carocad09:06:51

so I have to work with what I have at hand and I also dont want to reinvent the wheel (i.e. provide my own auth service)

carocad09:06:25

can you actually provide me some resources about that client-side cookie? I would love to know more about it

pesterhazy11:06:29

afaik it's not documented in the react-native docs, but that's how it works, just like a browser

pesterhazy11:06:29

afaik it's not documented in the react-native docs, but that's how it works, just like a browser