feat: Connections Tabs

Added a connections tab, now you can enter GitHub creds and store them in cookies like the API Keys
This commit is contained in:
Dustin Loring
2024-12-09 09:26:39 -05:00
parent 178653dbed
commit 9aaa3b560c
3 changed files with 79 additions and 31 deletions

View File

@@ -15,6 +15,7 @@ import { Octokit, type RestEndpointMethodTypes } from '@octokit/rest';
import * as nodePath from 'node:path';
import { extractRelativePath } from '~/utils/diff';
import { description } from '~/lib/persistence';
import Cookies from 'js-cookie';
export interface ArtifactState {
id: string;
@@ -396,15 +397,14 @@ export class WorkbenchStore {
return syncedFiles;
}
async pushToGitHub(repoName: string, githubUsername: string, ghToken: string) {
async pushToGitHub(repoName: string, githubUsername?: string, ghToken?: string) {
try {
// Get the GitHub auth token from environment variables
const githubToken = ghToken;
// Use cookies if username and token are not provided
const githubToken = ghToken || Cookies.get('githubToken');
const owner = githubUsername || Cookies.get('githubUsername');
const owner = githubUsername;
if (!githubToken) {
throw new Error('GitHub token is not set in environment variables');
if (!githubToken || !owner) {
throw new Error('GitHub token or username is not set in cookies or provided.');
}
// Initialize Octokit with the auth token
@@ -501,7 +501,8 @@ export class WorkbenchStore {
alert(`Repository created and code pushed: ${repo.html_url}`);
} catch (error) {
console.error('Error pushing to GitHub:', error instanceof Error ? error.message : String(error));
console.error('Error pushing to GitHub:', error);
throw error; // Rethrow the error for further handling
}
}
}