add login support (wonky still)

This commit is contained in:
2024-07-08 18:41:12 +02:00
parent 7b9f93448b
commit d85df4c308
21 changed files with 1183 additions and 304 deletions

View File

@@ -9,9 +9,14 @@ import type {
GetTableForeignKeysArgs,
GetTableIndexesArgs,
GetTablesListArgs,
QueryRawSqlArgs,
} from "./db.types";
export const useLoginMutation = () => {
return useMutation({
mutationFn: dbService.login,
});
};
export const useDatabasesListQuery = () => {
return useQuery({
queryKey: [DB_QUERY_KEYS.DATABASES.ALL],
@@ -90,7 +95,6 @@ export const useQueryRawSqlMutation = () => {
}
toast.error(error.message);
},
mutationFn: ({ query }: QueryRawSqlArgs) =>
dbService.queryRawSql({ query }),
mutationFn: dbService.queryRawSql,
});
};

View File

@@ -1,5 +1,6 @@
import ky from 'ky'
import ky from "ky";
export const dbInstance = ky.create({
prefixUrl: 'http://localhost:3000'
})
credentials: "include",
prefixUrl: "http://localhost:3000",
});

View File

@@ -9,6 +9,8 @@ import type {
GetTableIndexesArgs,
GetTablesListArgs,
GetTablesListResponse,
LoginArgs,
LoginResponse,
QueryRawSqlArgs,
QueryRawSqlResponse,
TableColumns,
@@ -17,6 +19,12 @@ import type {
} from "@/services/db/db.types";
class DbService {
login(data: LoginArgs) {
return dbInstance
.post("api/auth/login", { json: data })
.json<LoginResponse>();
}
getDatabasesList() {
return dbInstance.get("api/databases").json<DatabasesResponse>();
}

View File

@@ -1,3 +1,21 @@
export type LoginArgs =
| {
username: string;
password: string;
host: string;
type: string;
port: string;
ssl: string;
database: string;
}
| {
connectionString: string;
};
export type LoginResponse = {
success: boolean;
};
export type DatabasesResponse = Array<string>;
// Tables List