feat: implement auth, projects, and frontend foundation
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import axios from "axios";
|
||||
|
||||
const BASE_URL = import.meta.env.VITE_API_BASE_URL ?? "http://localhost:8000";
|
||||
|
||||
export const apiClient = axios.create({
|
||||
baseURL: BASE_URL,
|
||||
withCredentials: true,
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
});
|
||||
|
||||
export const shouldSkipAuthRedirect = (path: string): boolean => {
|
||||
return path.startsWith("/login") || path.startsWith("/auth");
|
||||
};
|
||||
|
||||
apiClient.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
const status = error?.response?.status;
|
||||
if (status === 401 && !shouldSkipAuthRedirect(window.location.pathname)) {
|
||||
window.location.assign("/auth/login");
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,13 @@
|
||||
import { apiClient } from "./client";
|
||||
|
||||
export type DashboardSummary = {
|
||||
projects: number;
|
||||
repositories: number;
|
||||
sshKeys: number;
|
||||
recentActivity: string[];
|
||||
};
|
||||
|
||||
export const getDashboardSummary = async (): Promise<DashboardSummary> => {
|
||||
const response = await apiClient.get<DashboardSummary>("/dashboard/summary");
|
||||
return response.data;
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
import { apiClient } from "./client";
|
||||
import type { Project } from "../types";
|
||||
|
||||
export type ProjectCreateInput = {
|
||||
name: string;
|
||||
description?: string | null;
|
||||
};
|
||||
|
||||
export type ProjectUpdateInput = {
|
||||
name?: string | null;
|
||||
description?: string | null;
|
||||
};
|
||||
|
||||
export type SetDefaultSSHKeyInput = {
|
||||
ssh_key_id: string;
|
||||
};
|
||||
|
||||
export const listProjects = async (): Promise<Project[]> => {
|
||||
const response = await apiClient.get<Project[]>("/projects");
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const createProject = async (
|
||||
input: ProjectCreateInput
|
||||
): Promise<Project> => {
|
||||
const response = await apiClient.post<Project>("/projects", input);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const updateProject = async (
|
||||
projectId: string,
|
||||
input: ProjectUpdateInput
|
||||
): Promise<Project> => {
|
||||
const response = await apiClient.patch<Project>(`/projects/${projectId}`, input);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const deleteProject = async (projectId: string): Promise<void> => {
|
||||
await apiClient.delete(`/projects/${projectId}`);
|
||||
};
|
||||
|
||||
export const setDefaultSSHKey = async (
|
||||
projectId: string,
|
||||
input: SetDefaultSSHKeyInput
|
||||
): Promise<Project> => {
|
||||
const response = await apiClient.patch<Project>(
|
||||
`/projects/${projectId}/default-ssh-key`,
|
||||
input
|
||||
);
|
||||
return response.data;
|
||||
};
|
||||
Reference in New Issue
Block a user