Skip to content

Epic: Web UI (2/4) - Frontend Foundation & Authentication #54

Closed

Description

@integry

Epic: GitFix Web Management UI

This is the second of four issues to build the web UI.

Previous Issue: #53

This Issue (2/4): Frontend Foundation & Authentication

This task focuses on setting up the React frontend application and implementing the crucial GitHub authentication layer.

High-Level Goal

  • Bootstrap a new React application using Vite and Tailwind CSS.
  • Implement the full GitHub OAuth2 login flow using Passport.js on the backend.
  • Create protected routes to secure the dashboard from public access.
  • Build the main application layout (e.g., sidebar, header, content area).

Implementation Steps

  1. Frontend Setup:
    • In the packages/dashboard directory, create a client subdirectory.
    • Initialize a new React project using Vite: npm create vite@latest client -- --template react-ts.
    • Add and configure Tailwind CSS for styling.
  2. Backend Authentication:
    • Add passport, passport-github2, and express-session to the dashboard-api service.
    • Create a GitHub OAuth App and add the credentials to the .env file.
    • Configure the Passport GitHub strategy.
    • Implement the /auth/github and /auth/github/callback routes.
    • Create a middleware ensureAuthenticated to protect API endpoints.
  3. Frontend Authentication Flow:
    • Create a LoginPage.js component with a "Login with GitHub" button that links to /api/auth/github.
    • Set up client-side routing (e.g., using react-router-dom) to handle protected routes. If a user is not authenticated, they should be redirected to the login page.

Activity

  1. integry commented on Sep 12, 2025

    @integry
    OwnerAuthor

    Suggested Implementation: Passport.js Auth Backend

    This code provides a robust starting point for the GitHub authentication flow in the Express API.

    Reasoning:

    • Standard Practice: Uses Passport.js, the standard for authentication in the Node.js ecosystem.
    • Session-Based: Establishes a server-side session, which is a secure and common way to handle user logins in a web application.
    • Extensible: As discussed in our planning, this pattern makes it easy to add other authentication strategies (Bitbucket, etc.) in the future.
    // packages/dashboard/auth.js
    import passport from 'passport';
    import { Strategy as GitHubStrategy } from 'passport-github2';
    import session from 'express-session';
    
    export function setupAuth(app) {
        app.use(session({
            secret: process.env.SESSION_SECRET,
            resave: false,
            saveUninitialized: false,
        }));
        app.use(passport.initialize());
        app.use(passport.session());
    
        passport.use(new GitHubStrategy({
            clientID: process.env.GH_OAUTH_CLIENT_ID,
            clientSecret: process.env.GH_OAUTH_CLIENT_SECRET,
            callbackURL: 'http://localhost:4000/api/auth/github/callback',
        },
        (accessToken, refreshToken, profile, done) => {
            // Here you would find or create a user in your database.
            // For now, we'll just pass the profile through.
            console.log('User authenticated:', profile.username);
            return done(null, profile);
        }));
    
        passport.serializeUser((user, done) => done(null, user));
        passport.deserializeUser((obj, done) => done(null, obj));
    
        // Routes
        app.get('/api/auth/github', passport.authenticate('github', { scope: ['user:email', 'read:org'] }));
    
        app.get('/api/auth/github/callback',
            passport.authenticate('github', { failureRedirect: '/login' }),
            (req, res) => {
                // Successful authentication, redirect to the dashboard.
                res.redirect('/');
            }
        );
    
        app.get('/api/auth/logout', (req, res) => {
            req.logout();
            res.redirect('/login');
        });
    
        app.get('/api/auth/user', ensureAuthenticated, (req, res) => {
            res.json(req.user);
        });
    }
    
    export function ensureAuthenticated(req, res, next) {
        if (req.isAuthenticated()) {
            // Here you can add authorization logic, e.g.,
            // check if req.user.username is part of a specific GitHub org.
            return next();
        }
        res.status(401).json({ error: 'Unauthorized' });
    }
  2. propr-dev commented on Sep 12, 2025

    @propr-dev
    Contributor

    🤖 AI processing has started for this issue using claude-opus-4-20250514 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Model: claude-opus-4-20250514
    • Branch: ai-fix/54-epic-web-ui-2-4-frontend--20250913-0027-claude-opus-4-20250514-dle
    • Base Branch: main
    • Worktree: issue-54-20250913-0027-claude-opus-4-20250514-dle
  3. added a commit that references this issue on Sep 12, 2025
  4. added a commit that references this issue on Sep 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions