code100x / chess

A multiplayer chess platform
https://chess.100xdevs.com/
1.62k stars 581 forks source link

Issue in auth in react native #112

Open marssarthak opened 6 months ago

marssarthak commented 6 months ago

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 commented 6 months ago

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

RahulMishra0722 commented 6 months ago

did you guys not get this error

Screenshot 2024-04-20 at 1 08 02 PM
marssarthak commented 6 months ago

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

TanmayDhobale commented 6 months ago

@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 commented 6 months ago

@marssarthak can i work on this ?

marssarthak commented 6 months ago

@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.

TanmayDhobale commented 6 months ago

@marssarthak sounds good !!

TanmayDhobale commented 6 months ago

@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

marssarthak commented 6 months ago

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?

TanmayDhobale commented 6 months ago

@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.

marssarthak commented 6 months ago

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

TanmayDhobale commented 6 months ago

Give me 15 min @marssarthak

TanmayDhobale commented 6 months ago

@marssarthak can u check the pull request #160

marssarthak commented 6 months ago

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

TanmayDhobale commented 6 months ago

yes @marssarthak give ur id ill text u

marssarthak commented 6 months ago

here- ***

TanmayDhobale commented 6 months ago

done