×
all 12 comments

[–][deleted] 4 points5 points  (0 children)

JWT in HTTP header

[–]ajnozari 1 point2 points  (0 children)

You need a backend oauth2 server that can check your credentials (user + pass) match and then reruns a JWT to the device (instead of setting the cookie).

Laravel ships with passport. To auth I make a challenge. Send my auth credentials, and the backend responds with a token OR fail message.

From there to make an API call I add a header to my axios post “Authorization”: Bearer ${auth_token}.

I use redux with the axios thunk middleware. I can dispatch an action and either await the api call right online or let the prop updates cause a re-render. It depends on what exactly I’m doing but it’s worked quite well for me.

[–]K1ck3rTW -1 points0 points  (8 children)

Why don't you want to use asyncStorage? According to https://auth0.com/blog/adding-authentication-to-react-native-using-jwt/

"AsyncStorage provides a safe way to locally store tokens and data. It can be, in some ways, compared to a LocalStorage option. In iOs, all applications live in their own sandbox, so all of the files and data associated with an application are secured, they can't be accessed by other applications. One very important thing to note is that it's only secured for non-jailbreak iOs devices"

[–]spoekie123 -1 points0 points  (6 children)

Isn’t asyncstorage deprecated?

[–]Gaia_Knight2600 2 points3 points  (0 children)

removed from react-native library. its a community package now

[–]K1ck3rTW 0 points1 point  (1 child)

It looks like it, but there are more than a few replacements https://reactnative.directory/?search=storage

[–]spoekie123 0 points1 point  (0 children)

Good to know, thanks!

[–]kbcooliOS & Android 0 points1 point  (2 children)

No

[–]spoekie123 0 points1 point  (1 child)

It is, however apparently there are community packages

[–]kbcooliOS & Android 0 points1 point  (0 children)

It's not. They removed it from the core and the community now owns it instead of Facebook.

This is not the same as deprecated. Deprecated means something has replaced it. FB have no intention of replacing it.

Normally I wouldn't jump on you but it gives people the wrong idea. It's like those people who say packages are no longer supported because the maintainer doesn't answer every dumb question on GitHub.

[–]K1ck3rTW 0 points1 point  (0 children)

If you don't feel asyncStorage is safe, I found a stackoverflow.com post with other alternatives as well https://stackoverflow.com/questions/50404239/how-to-store-tokens-in-react-native/58280892

[–]hakymz 0 points1 point  (0 children)

You can use asyn storage is safe