This document describes the frontend integration with the Patchwork backend API.
Current Backend: http://7nonainmv1.loclx.io
To change the backend URL, edit /src/shared/config/api.ts:
export const API_BASE_URL = 'http://your-backend-url';The application uses GitHub OAuth for authentication. There is no traditional email/password signup or signin.
-
User Clicks "Sign In/Sign Up"
- Both signin and signup redirect to the same GitHub OAuth flow
- No role selection is needed upfront - roles are assigned by the backend
-
GitHub OAuth Flow
- User is redirected to
http://7nonainmv1.loclx.io/auth/github/login/start - User authorizes Grainlify on GitHub
- GitHub redirects back to backend's callback endpoint
- Backend processes OAuth and redirects to frontend:
/auth/callback?token=<jwt_token>
- User is redirected to
-
Frontend Callback Handling
- The
/auth/callbackroute extracts the JWT token from URL - Token is stored in localStorage as
patchwork_jwt - User info is fetched from
/meendpoint - User is redirected to
/dashboard
- The
-
Authenticated Requests
- All subsequent API calls include:
Authorization: Bearer <jwt_token> - If token expires (401 response), user is redirected to signin
- All subsequent API calls include:
The AuthContext manages authentication state:
isAuthenticated- Whether user is logged inisLoading- Whether auth state is being checkeduserRole- User's role (contributor, maintainer, admin)userId- User's UUIDlogin(token)- Store token and fetch user infologout()- Clear token and user state
All API calls are centralized in /src/shared/api/client.ts.
import { getCurrentUser, getUserProfile } from '@/shared/api/client';
// Get current user (requires authentication)
const user = await getCurrentUser();
console.log(user.id, user.role);
// Get user profile
const profile = await getUserProfile();
console.log(profile.contributions_count);getCurrentUser()- Get current user info (id, role)getGitHubLoginUrl()- Get GitHub OAuth URLgetGitHubStatus()- Check if GitHub account is linked
getUserProfile()- Get contributions, languages, ecosystemsgetProfileCalendar()- Get 365-day contribution calendargetProfileActivity(limit, offset)- Get paginated activity feed
getPublicProjects(params)- Get filtered list of projectsgetProjectFilters()- Get available filters (languages, tags, etc.)getMyProjects()- Get projects owned by user (maintainers)createProject(data)- Create a new projectverifyProject(id)- Verify project ownershipsyncProject(id)- Sync project data from GitHub
getEcosystems()- Get list of ecosystems
startKYCVerification()- Start KYC verification sessiongetKYCStatus()- Get KYC verification status
/src/shared/
├── api/
│ ├── client.ts # API client with all endpoints
│ └── index.ts # Exports
├── config/
│ └── api.ts # API configuration (base URL)
└── contexts/
└── AuthContext.tsx # Authentication state management
/src/app/pages/
├── AuthCallbackPage.tsx # OAuth callback handler
└── ...
/src/features/auth/pages/
├── SignInPage.tsx # GitHub OAuth signin
└── SignUpPage.tsx # GitHub OAuth signup
JWT tokens are stored in localStorage with the key patchwork_jwt.
- This is suitable for development and prototyping
- For production, consider using httpOnly cookies for better security
- Never expose sensitive data in the JWT payload
The API client automatically handles common errors:
- 401 Unauthorized - Token expired/invalid → Clears token and redirects to signin
- Other errors - Throws error with message from backend
Example:
try {
const profile = await getUserProfile();
} catch (error) {
console.error(error.message); // "Authentication failed. Please sign in again."
}The backend must allow requests from your frontend domain.
For development, make sure the backend allows:
http://localhost:5173(or your Vite dev server port)- Or configure CORS to allow all origins (development only)
- ✅ Authentication - Implemented (GitHub OAuth)
- ⬜ Profile Pages - Fetch real data from
/profileendpoints - ⬜ Projects Browsing - Fetch from
/projectsendpoint - ⬜ Ecosystems - Fetch from
/ecosystemsendpoint - ⬜ Maintainer Dashboard - Fetch from
/projects/mineendpoint - ⬜ KYC Verification - Integrate KYC flow
- ⬜ Admin Panel - Implement admin endpoints (if user is admin)
- Start your frontend:
npm run dev - Click "Sign In" or "Sign Up"
- You'll be redirected to GitHub OAuth
- After authorization, you'll be redirected back to
/auth/callback - The app will extract the token and log you in
- You'll be redirected to
/dashboard
- Check if backend is running at the configured URL
- Verify CORS is configured correctly
- Check browser console for detailed errors
- Verify backend's
PUBLIC_BASE_URLincludes your frontend URL - Check that
/auth/callbackroute is registered in your app
- Check backend's JWT expiration settings
- Verify token is being stored correctly in localStorage
For better configuration management, you can use environment variables:
# .env.local
VITE_API_BASE_URL=http://7nonainmv1.loclx.ioThen update /src/shared/config/api.ts:
export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8080';