Signing in / register from React Native to Web2py?

72 views
Skip to first unread message

Mika Sjöman

unread,
Mar 13, 2017, 6:06:31 PM3/13/17
to web2py-users
Hi

After extensive searching in the forum, docs and the internet, I feel that I can post the question here. I am building a React Native application, which means I don't have access to localstorage (this is not a web-app) - I think that I need to save some kind of login token in my React native state variable and re-send it for every request (being my best guess). Other implementations I found on the forum uses web-implementations with Angular, but since this is not a web-page, I need to handle this using just JS. 

I wonder if anyone here has experience of doing something similar? Is it possible to use a POST request using say axios to do something like this towards the login/register:

axios
.post('myWeb2pyBackend/myapp/user', { username: 'myloginname', password: 'test2' }) .then(function (response) { console.log(response); // if OK, save some token to state and resend with every GET request later }) .catch(function (error) { console.log(error); });

Observe that this is Node.js that doesn't have access to the browser window variable or any other browser specific thing like localstorage. Would it be possible to get a JSON web token as a response from web2py that I resend to the server when the user asks for other resources which requires a signed in user? 

Cheers

Dave S

unread,
Mar 13, 2017, 7:07:05 PM3/13/17
to web2py-users


On Monday, March 13, 2017 at 3:06:31 PM UTC-7, Mika Sjöman wrote:
 
Would it be possible to get a JSON web token as a response from web2py that I resend to the server when the user asks for other resources which requires a signed in user? 


This part I can answer.  Niphlod's contributions for JWT are 2.14.6; see gluon/tools.py for class AuthJWT, about line #1132.

/dps


Oasis Agano

unread,
Jun 21, 2017, 4:30:12 PM6/21/17
to web2py-users
Hello, did you find the way of doing this i want to do the same thing in react native
Reply all
Reply to author
Forward
0 new messages