mirror of
https://github.com/shishantbiswas/bknd-examples.git
synced 2026-03-17 02:36:03 +00:00
cleanups/refactor of the entire main branch
All checks were successful
Build and Push to Gitea Registry / build-and-push (push) Successful in 6m40s
All checks were successful
Build and Push to Gitea Registry / build-and-push (push) Successful in 6m40s
This commit is contained in:
31
src/lib/bknd.ts
Normal file
31
src/lib/bknd.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { App } from "bknd";
|
||||
import config from "../../bknd.config";
|
||||
import { getApp as getBkndApp } from "bknd/adapter/tanstack-start";
|
||||
|
||||
declare global {
|
||||
var __bknd: App | undefined
|
||||
}
|
||||
|
||||
const getApp = async () => {
|
||||
if (!global.__bknd) {
|
||||
global.__bknd = await getBkndApp(config, process.env);
|
||||
}
|
||||
return global.__bknd;
|
||||
}
|
||||
|
||||
export async function getApi({
|
||||
headers,
|
||||
verify,
|
||||
}: {
|
||||
verify?: boolean;
|
||||
headers?: Headers;
|
||||
}) {
|
||||
const app = await getApp();
|
||||
if (verify) {
|
||||
const api = app.getApi({ headers });
|
||||
await api.verifyAuth();
|
||||
return api;
|
||||
}
|
||||
|
||||
return app.getApi();
|
||||
}
|
||||
Reference in New Issue
Block a user