Dev
Dev
Explore posts from servers
CDCloudflare Developers
Created by Dev on 1/25/2025 in #pages-help
Help: Binding undefined during build process
I'm creating a rag app entirely with cloudflare and next-on-pages and hono as api server however, when i try to access the binding, it gives this error.
[wrangler:inf] GET /chat 200 OK (21ms)
[wrangler:inf] GET /_next/static/chunks/808-024d9e9f46b0d710.js 200 OK (7ms)
✘ [ERROR] Error creating context: TypeError: Cannot destructure property 'AI' of 'e.env' as it is undefined.

✘ [ERROR] Environment not found
[wrangler:inf] POST /api/context/text 500 Internal Server Error (79ms)
[wrangler:inf] GET /chat 200 OK (21ms)
[wrangler:inf] GET /_next/static/chunks/808-024d9e9f46b0d710.js 200 OK (7ms)
✘ [ERROR] Error creating context: TypeError: Cannot destructure property 'AI' of 'e.env' as it is undefined.

✘ [ERROR] Environment not found
[wrangler:inf] POST /api/context/text 500 Internal Server Error (79ms)
heres the code i'm using
const app = new Hono<{ Bindings: CloudflareEnv }>();
//`CloudflareEnv` is generated by running the command cf-typegen

app.post("/", zValidator("json", textContextSchema), async (c) => {
..
const { AI, VECTORIZE } = c.env;
if (c.env) {
// Debugging
console.log("Environment Bindings: ", c.env);
console.log("AI Binding: ", AI);
console.log("VECTORIZE Binding: ", VECTORIZE);

const embeddingResult = await c.env.AI.run(
"@cf/baai/bge-base-en-v1.5",
{
text: content,
},
);

const embedding = embeddingResult.data[0];

// 6. Save the embeddings into Vectorize
if (embedding && embedding.length > 0) {
await c.env.VECTORIZE.insert([
{
id: GenerateUUID(),
values: embedding,
metadata: { text: content, context_id: contextId },
},
]);
} else {
console.error("Invalid embedding:", embedding);
}
} else {
console.error("Environment not found");
return c.json({ error: "Environment bindings inaccessible" }, 500);
}
...
const app = new Hono<{ Bindings: CloudflareEnv }>();
//`CloudflareEnv` is generated by running the command cf-typegen

app.post("/", zValidator("json", textContextSchema), async (c) => {
..
const { AI, VECTORIZE } = c.env;
if (c.env) {
// Debugging
console.log("Environment Bindings: ", c.env);
console.log("AI Binding: ", AI);
console.log("VECTORIZE Binding: ", VECTORIZE);

const embeddingResult = await c.env.AI.run(
"@cf/baai/bge-base-en-v1.5",
{
text: content,
},
);

const embedding = embeddingResult.data[0];

// 6. Save the embeddings into Vectorize
if (embedding && embedding.length > 0) {
await c.env.VECTORIZE.insert([
{
id: GenerateUUID(),
values: embedding,
metadata: { text: content, context_id: contextId },
},
]);
} else {
console.error("Invalid embedding:", embedding);
}
} else {
console.error("Environment not found");
return c.json({ error: "Environment bindings inaccessible" }, 500);
}
...
this block always fails my wrangler-toml
[ai]
binding = "AI"

[[vectorize]]
binding = "VECTORIZE"
index_name = "dropbase-index"
[ai]
binding = "AI"

[[vectorize]]
binding = "VECTORIZE"
index_name = "dropbase-index"
17 replies
KKinde
Created by Dev on 7/15/2024 in #💻┃support
Session cookie does not persist after reload in React SDK
main.js:
<KindeProvider
clientId={import.meta.env.VITE_KINDE_CLIENT_ID}
domain={import.meta.env.VITE_KINDE_DOMAIN}
{redirectUri}
{redirectUri.replace("/dashboard", "/")}
>
<ThemeProvider>
<App />
</ThemeProvider>
</KindeProvider>
<KindeProvider
clientId={import.meta.env.VITE_KINDE_CLIENT_ID}
domain={import.meta.env.VITE_KINDE_DOMAIN}
{redirectUri}
{redirectUri.replace("/dashboard", "/")}
>
<ThemeProvider>
<App />
</ThemeProvider>
</KindeProvider>
i have setup admin subdomain in my site, thats why the redirectUri and logoutUri is different from what's defined in the react setup docs So, when i try to login using this setting, it logs in for a moment but when i reload, it logs me out immediately i had a look in the applications tab in the browser console, the cookies had some enduser_session_id field in it, and when i reload, this field vanishes I tried using isDangerouslyUseLocalStorage={true} in the above setting, it kept me logged in until i manually log out, the local storage had kinde_refresh_token this time and if i log out, the kinde_refresh_token & enduser_session_id vanishes from local storage and cookies resp. I cannot keep using isDangerouslyUseLocalStorage={true} as it is not secure, and i'm wondering why the kinde_refresh_token not getting saved in the cookie instead of local storage? is this a bug? if not is there a workaround to make it work
2 replies