Taylordb client was created
This commit is contained in:
parent
fb7e614dac
commit
0fb69ae14a
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -26,5 +26,4 @@ dist-ssr
|
|||
.env*
|
||||
.aider*
|
||||
|
||||
src/lib/taylordb.types.ts
|
||||
src/lib/taylordb.client.ts
|
||||
src/lib/taylordb.types.ts
|
||||
28
src/lib/taylordb.client.ts
Normal file
28
src/lib/taylordb.client.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { createQueryBuilder } from "@taylordb/query-builder";
|
||||
import type { TaylorDatabase } from "./taylordb.types";
|
||||
|
||||
let apiKey: string | undefined;
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
const apiKeyFromParams = searchParams.get("apiKey");
|
||||
|
||||
if (apiKeyFromParams) {
|
||||
// Store in session storage if found in search params
|
||||
sessionStorage.setItem("authToken", apiKeyFromParams);
|
||||
apiKey = apiKeyFromParams;
|
||||
} else {
|
||||
// If not in search params, try to get it from session storage
|
||||
apiKey = sessionStorage.getItem("authToken") ?? undefined;
|
||||
}
|
||||
}
|
||||
|
||||
if (!apiKey) {
|
||||
throw new Error("No authentication token found");
|
||||
}
|
||||
|
||||
export const queryBuilder = createQueryBuilder<TaylorDatabase>({
|
||||
baseUrl: import.meta.env.VITE_TAYLORDB_BASE_URL,
|
||||
baseId: import.meta.env.VITE_TAYLORDB_BASE_ID,
|
||||
apiKey,
|
||||
});
|
||||
|
|
@ -14,6 +14,8 @@ paths:
|
|||
environment:
|
||||
envVars:
|
||||
NODE_ENV: production
|
||||
VITE_TAYLORDB_BASE_ID: vars.TAYLORDB_SERVER_ID
|
||||
VITE_TAYLORDB_BASE_URL: vars.TAYLORDB_BASE_URL
|
||||
|
||||
install:
|
||||
commands:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user