Can express-session be used in React Native?

Viewed 25

My React Native app needs to use sessions for when users are signed in, but I'm not sure how to implement it. At first I thought I'd need AsyncStorage to store the session ID and attach it to each request to the server, but now I'm wondering if any additional code is required on the client side.

For example, I believe express-session sets a cookie automatically in the browser which means you just have to send the cookie. Is this the same for React Native/mobile applications? In other words, if I send a response that contains a cookie will that cookie automatically be attached to each future request, or do I need to store it somehow?

1 Answers

Have you tried axios ?, it automatically set the cookie it receive to client when you specify the option withCredentials: true.
example:

axios({
            method: 'post',
            url: '/api/auth/login',
            data: {
                username: username,
                hashpass: hash(password) 
            },
            withCredentials: true
        }).then(res => console.log('login success'))
            .catch(res => {
                   console.log('error')
            })
Related