From 2b28bff45b3b39c637b8736928ea3cd031e71fe6 Mon Sep 17 00:00:00 2001 From: Sachin Panayil Date: Wed, 10 Dec 2025 15:07:10 -0500 Subject: [PATCH 1/3] removing localStorage dependency --- frontend/js/autoGenerateFields.js | 119 ++++++++++++++++-------------- 1 file changed, 65 insertions(+), 54 deletions(-) diff --git a/frontend/js/autoGenerateFields.js b/frontend/js/autoGenerateFields.js index 2f065a5..2609cdf 100644 --- a/frontend/js/autoGenerateFields.js +++ b/frontend/js/autoGenerateFields.js @@ -63,54 +63,61 @@ const API_CONFIG = { ENDPOINTS: { INITIATE: '/auth/initiate', CALLBACK: '/auth/callback', + STATUS: '/auth/status', + LOGOUT: '/auth/logout', GET_REPOS: '/repos' } }; -const AUTH_STORAGE_KEY = 'github_oauth_session'; +let isAuthenticatedState = false; -function getAuthToken() { - return localStorage.getItem(AUTH_STORAGE_KEY); -} - -function setAuthToken(token) { - localStorage.setItem(AUTH_STORAGE_KEY, token); -} - -function clearAuthToken() { - localStorage.removeItem(AUTH_STORAGE_KEY); +async function checkAuthStatus() { + try { + const response = await fetch(`${API_CONFIG.BASE_URL}${API_CONFIG.ENDPOINTS.STATUS}`, { + method: 'GET', + credentials: 'include' + }); + + if (!response.ok) { + return false; + } + + const data = await response.json(); + return data.authenticated === true; + } catch (error) { + console.error('Error checking auth status:', error); + return false; + } } function isAuthenticated() { - return !!getAuthToken(); + return isAuthenticatedState; } // OAUTH FLOW HANDLING async function handleOAuthCallback() { const urlParams = new URLSearchParams(window.location.search); - const sessionToken = urlParams.get('session'); + const authSuccess = urlParams.get('auth'); + const error = urlParams.get('error'); - console.log('Session token from URL:', sessionToken); + if (error) { + notificationSystem.error(error); + window.history.replaceState({}, document.title, window.location.pathname); + return; + } - try { - if (sessionToken) { - setAuthToken(sessionToken); - notificationSystem.success('Successfully connected to GitHub!'); - window.history.replaceState({}, document.title, window.location.pathname); - - initializeAuthUI(); - await fetchUserRepositories(); - } else if (getAuthToken()) { - console.log("getting auth token") - notificationSystem.success('Successfully connected to GitHub!'); + if (authSuccess === 'success') { + notificationSystem.success('Successfully connected to GitHub!'); + window.history.replaceState({}, document.title, window.location.pathname); + } - initializeAuthUI(); - await fetchUserRepositories(); - } - } catch (error) { - console.error('OAuth callback error:', error); - notificationSystem.error(error.message); + isAuthenticatedState = await checkAuthStatus(); + + initializeAuthUI(); + + if (isAuthenticatedState) { + await fetchUserRepositories(); } } @@ -119,31 +126,46 @@ function initiateGitHubOAuth() { window.location.href = initiateUrl; } -function disconnectGitHub() { - clearAuthToken(); - notificationSystem.success('Disconnected from GitHub'); - initializeAuthUI(); +async function disconnectGitHub() { + try { + const response = await fetch(`${API_CONFIG.BASE_URL}${API_CONFIG.ENDPOINTS.LOGOUT}`, { + method: 'POST', + credentials: 'include' + }); + + if (response.ok) { + isAuthenticatedState = false; + cachedRepositories = []; + notificationSystem.success('Disconnected from GitHub'); + initializeAuthUI(); + } else { + throw new Error('Logout failed'); + } + } catch (error) { + console.error('Error disconnecting:', error); + notificationSystem.error('Failed to disconnect. Please try again.'); + } } // REPOSITORY FETCHING async function fetchUserRepositories() { - const sessionToken = getAuthToken(); - - if (!sessionToken) { - console.error('No session token available'); - return; - } - try { const response = await fetch(`${API_CONFIG.BASE_URL}${API_CONFIG.ENDPOINTS.GET_REPOS}`, { + method: 'GET', + credentials: 'include', headers: { - 'Authorization': `Bearer ${sessionToken}`, 'Content-Type': 'application/json' } }); if (!response.ok) { + if (response.status === 401) { + isAuthenticatedState = false; + initializeAuthUI(); + notificationSystem.error('Session expired. Please reconnect to GitHub.'); + return; + } throw new Error('Failed to fetch repositories'); } @@ -211,7 +233,6 @@ function initializeAuthUI() { // API CALLS async function getRepoInformationAuth(repoInfo) { - const sessionToken = getAuthToken(); const baseURL = "https://api.github.com/repos/"; const endpoint = `${baseURL}${repoInfo.organization}/${repoInfo.repository}`; @@ -219,10 +240,6 @@ async function getRepoInformationAuth(repoInfo) { const headers = { 'Accept': 'application/vnd.github.v3+json' }; - - if (sessionToken) { - headers['Authorization'] = `Bearer ${sessionToken}`; - } const response = await fetch(endpoint, { headers }); @@ -238,17 +255,12 @@ async function getRepoInformationAuth(repoInfo) { } async function getRepoLanguagesAuth(repoInfo) { - const sessionToken = getAuthToken(); const endpoint = `https://api.github.com/repos/${repoInfo.organization}/${repoInfo.repository}/languages`; try { const headers = { 'Accept': 'application/vnd.github.v3+json' }; - - if (sessionToken) { - headers['Authorization'] = `Bearer ${sessionToken}`; - } const response = await fetch(endpoint, { headers }); @@ -587,7 +599,6 @@ window.disconnectGitHub = disconnectGitHub; document.addEventListener("DOMContentLoaded", function () { setupFormHandler(); setupNotificationSystem(); - initializeAuthUI(); handleOAuthCallback(); setupDropdownHandler(); }); \ No newline at end of file From 08d47c8d930e84c8f1c578b13dd4576f7009a4fe Mon Sep 17 00:00:00 2001 From: Sachin Panayil Date: Wed, 10 Dec 2025 15:20:44 -0500 Subject: [PATCH 2/3] checking to follow the flow --- frontend/js/autoGenerateFields.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/frontend/js/autoGenerateFields.js b/frontend/js/autoGenerateFields.js index 2609cdf..4d80b72 100644 --- a/frontend/js/autoGenerateFields.js +++ b/frontend/js/autoGenerateFields.js @@ -97,10 +97,14 @@ function isAuthenticated() { // OAUTH FLOW HANDLING async function handleOAuthCallback() { + console.log('handleOAuthCallback started'); + const urlParams = new URLSearchParams(window.location.search); const authSuccess = urlParams.get('auth'); const error = urlParams.get('error'); + console.log('URL params:', { authSuccess, error }); + if (error) { notificationSystem.error(error); window.history.replaceState({}, document.title, window.location.pathname); @@ -112,8 +116,13 @@ async function handleOAuthCallback() { window.history.replaceState({}, document.title, window.location.pathname); } + console.log('About to call checkAuthStatus'); + + // Check auth status from server isAuthenticatedState = await checkAuthStatus(); + console.log('checkAuthStatus returned:', isAuthenticatedState); + initializeAuthUI(); if (isAuthenticatedState) { From 679715003f7a5f86fb65d83429024eaabd2eb23a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 10 Dec 2025 20:21:10 +0000 Subject: [PATCH 3/3] update contributors information --- MAINTAINERS.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 40b7e13..5e74d4b 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -50,17 +50,17 @@ Total number of contributors: