-
Notifications
You must be signed in to change notification settings - Fork 71
Open
Labels
featureSuggest a new feature for the projectSuggest a new feature for the projecthacktoberfestIssues marked with this label are part of Hacktoberfest and open for contributionsIssues marked with this label are part of Hacktoberfest and open for contributionshelp wantedExtra attention is neededExtra attention is needed
Description
Problem or Need
The current authentication system only supports email and password registration. This requires users to create and remember a new password for our application. Offering social logins (OAuth) from providers like Google and GitHub is a standard feature for modern web apps that simplifies the registration and login process and can improve security.
Proposed Solution
Implement the OAuth 2.0 Authorization Code Grant flow manually to allow users to sign up and log in using their existing Google and GitHub accounts. This will involve adding "Continue with Google" and "Continue with GitHub" buttons that kick off the authentication sequence.
Expected Behavior
- On the Login or Register page, a user sees options to "Continue with Google" and "Continue with GitHub."
- The user clicks one of these buttons.
- They are redirected to the provider's official login page (Google or GitHub).
- After successfully authenticating with the provider, they are redirected back to the application and are automatically logged in.
- If it's their first time using this OAuth provider, a new account is created for them in the background.
Benefits
- Users can sign up with a single click, dramatically increasing the conversion rate for new user registration.
- Improved UX: Users don't need to create or remember another password.
- Enhanced Security: Leverages the robust security of major providers like Google and GitHub.
Possible Implementation
-
Backend:
- Add new credentials (Client ID, Client Secret, Callback URL) for both Google and GitHub to the backend
.env
file. These must be obtained from the Google Cloud Platform and GitHub Developer Settings. - Create two new routes for each provider. For Google, this would be:
GET /api/auth/google
: This endpoint constructs the full authorization URL with the necessary query parameters (client_id
,redirect_uri
,scope
,response_type=code
) and redirects the user to Google's authentication screen.GET /api/auth/google/callback
: This is theredirect_uri
that Google calls after the user authenticates. This controller function must:- Receive the temporary
code
from Google's query parameters. - Make a server-to-server
POST
request (usingaxios
) to Google's token endpoint to exchange thecode
for anaccess_token
andid_token
. - Decode or verify the
id_token
to get the user's profile information (email, name). - Use the email to find an existing user or create a new one in the database.
- Generate our application's own JWT for this user.
- Redirect the user back to a specific frontend URL, passing our JWT as a query parameter (e.g.,
https://paisable.netlify.app/auth/callback?token=...
).
- Receive the temporary
- Add new credentials (Client ID, Client Secret, Callback URL) for both Google and GitHub to the backend
-
Frontend:
- Add the "Continue with Google/GitHub" buttons to
LoginPage.jsx
andRegisterPage.jsx
. These buttons will be standard<a>
tags that link directly to the backend'sGET /api/auth/google
andGET /api/auth/github
endpoints. - Create a new page/route in the React app at
/auth/callback
. - Create a new
AuthCallbackPage.jsx
component. This component's purpose is to:- Run on page load.
- Parse the JWT from the URL's query parameters.
- Save the token to
localStorage
. - Update the
AuthContext
to establish the user's session. - Redirect the user to their
/dashboard
.
- Add the "Continue with Google/GitHub" buttons to
Alternatives Considered
- Using a dedicated authentication library like Passport.js is the industry-standard and recommended alternative. It abstracts away many of the complexities and potential security pitfalls of the OAuth 2.0 flow. This manual implementation is chosen for granular control.
Additional Notes
- This is an advanced feature that requires a thorough understanding of the full OAuth 2.0 flow.
- The implementation must strictly follow the official OAuth 2.0 documentation for each provider (Google and GitHub).
- Careful attention must be paid to security details, such as using the
state
parameter to prevent CSRF attacks and securely handling all tokens and secrets. - The implementation will require the contributor to set up their own developer applications on both Google Cloud Platform and GitHub to obtain the necessary API keys for local testing.
Metadata
Metadata
Assignees
Labels
featureSuggest a new feature for the projectSuggest a new feature for the projecthacktoberfestIssues marked with this label are part of Hacktoberfest and open for contributionsIssues marked with this label are part of Hacktoberfest and open for contributionshelp wantedExtra attention is neededExtra attention is needed
Type
Projects
Status
assigned