Taylordb client was created
This commit is contained in:
parent
fb7e614dac
commit
0fb69ae14a
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -27,4 +27,3 @@ dist-ssr
|
||||||
.aider*
|
.aider*
|
||||||
|
|
||||||
src/lib/taylordb.types.ts
|
src/lib/taylordb.types.ts
|
||||||
src/lib/taylordb.client.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:
|
environment:
|
||||||
envVars:
|
envVars:
|
||||||
NODE_ENV: production
|
NODE_ENV: production
|
||||||
|
VITE_TAYLORDB_BASE_ID: vars.TAYLORDB_SERVER_ID
|
||||||
|
VITE_TAYLORDB_BASE_URL: vars.TAYLORDB_BASE_URL
|
||||||
|
|
||||||
install:
|
install:
|
||||||
commands:
|
commands:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user