chess icon indicating copy to clipboard operation
chess copied to clipboard

Issue in auth in react native

Open marssarthak opened this issue 10 months ago • 17 comments

Hi. I am working on react native implementation. The frontend is ready, but I am unable to use the existing backend because of session based system.

The current auth system use passport.js to authenticate by redirecting to certain URL and getting cookie in return, but this cannot be done in react native, as no way to capture incoming httpsafe cookie.

I am confused how should I handle this, according to me session based system can be replaced by JWT based system, but i'll need to change entire auth flow.

Any suggestions on it?

marssarthak avatar Apr 20 '24 09:04 marssarthak

@TanmayDhobale Bro I see you wrote the auth code, Can you please suggest how can I extend it to integrate in mobile app?

marssarthak avatar Apr 20 '24 09:04 marssarthak

did you guys not get this error

Screenshot 2024-04-20 at 1 08 02 PM

RahulMishra0722 avatar Apr 20 '24 09:04 RahulMishra0722

No. I didn't run it locally, used harkirat's deployed links for now.

marssarthak avatar Apr 20 '24 09:04 marssarthak

@marssarthak you can switch to a JWT (JSON Web Token) based authentication system. JWTs are self-contained tokens that can be easily passed between the client and server, making them a good fit for mobile applications like React Native.

TanmayDhobale avatar Apr 20 '24 09:04 TanmayDhobale

@marssarthak can i work on this ?

TanmayDhobale avatar Apr 20 '24 09:04 TanmayDhobale

@TanmayDhobale Yes It would be great help.

I suggest this approach- I will make google base login system in react native using official SDK, and then I'll send the object returned from google signin to backend. Then backend should handle that user and send a JWT in return. Please correct me if wrong.

marssarthak avatar Apr 20 '24 09:04 marssarthak

@marssarthak sounds good !!

TanmayDhobale avatar Apr 20 '24 09:04 TanmayDhobale

@marssarthak @hkirat Here's how we can proceed with this :

React Native Frontend: Integrate the Google Sign-In SDK for React Native in our frontend codebase. Implement a screen or component that handles the Google Sign-In flow and retrieves the user's information (e.g., email, name) from the Google Sign-In SDK. Once the user successfully signs in with Google, send the retrieved user information to our backend for authentication and account creation/linking.

Backend: Implement a route (e.g., /auth/google) that accepts the user information from the React Native frontend. Verify the user information and create a new user account or link the existing account with the provided Google credentials. Generate and return a JWT (JSON Web Token) to the frontend upon successful authentication. and again in frontend Receive the JWT from the backend and securely store it (using AsyncStorage or react-native-keychain) for subsequent API requests. Implement a utility function or service to attach the JWT to the Authorization header or request body for protected API routes. Please let me know if you have any further suggestions

TanmayDhobale avatar Apr 20 '24 10:04 TanmayDhobale

Sounds great to me, I have a confusion, whether existing session based login will work on web, or should we migrate to JWT there also?

marssarthak avatar Apr 20 '24 10:04 marssarthak

@marssarthak i think For easier maintenance, it would be better to migrate the web application to a JWT-based authentication system as well. This way, both the React Native mobile app and the web application will share the same authentication mechanism and backend codebase.

TanmayDhobale avatar Apr 20 '24 10:04 TanmayDhobale

Hello @TanmayDhobale , any update on this task? Please ping me once when done.

marssarthak avatar Apr 21 '24 08:04 marssarthak

Give me 15 min @marssarthak

TanmayDhobale avatar Apr 21 '24 08:04 TanmayDhobale

@marssarthak can u check the pull request #160

TanmayDhobale avatar Apr 21 '24 08:04 TanmayDhobale

@TanmayDhobale Awesome work bro. I need some help in this backend, can I connect with you on discord?

marssarthak avatar Apr 21 '24 09:04 marssarthak

yes @marssarthak give ur id ill text u

TanmayDhobale avatar Apr 21 '24 09:04 TanmayDhobale

here- ***************

marssarthak avatar Apr 21 '24 09:04 marssarthak

done

TanmayDhobale avatar Apr 21 '24 09:04 TanmayDhobale