bkyerv
bkyerv
Explore posts from servers
CDCloudflare Developers
Created by bkyerv on 4/17/2025 in #workers-help
help with astro app backend functions on cloudflare workers
I've created a minimal reproducible repo on GitHub for an Astro app deployed to Cloudflare Workers. The app includes functionality to call a server-side function that should log messages, but I'm encountering issues: No messages appear in the Cloudflare Workers logs section after deployment No requests seem to be reaching the backend at all The client-side requests to the backend function aren't being processed https://github.com/bkyerv/astro-app/tree/main/src
4 replies
CDCloudflare Developers
Created by bkyerv on 4/16/2025 in #workers-help
help with astro framework deployment to cloudflare workers
I'm deploying an Astro project to Cloudflare Workers following the static assets guide, but I'm stuck with API routing. With React projects, Cloudflare creates separate src and worker folders, with backend code in the worker folder. However, my Astro project doesn't have a worker folder. I tried manually creating a worker folder with code to handle API routes, but all fetch requests to /api/... return 404 errors, despite my worker code being set up to respond with test messages. How do I correctly structure an Astro project for Cloudflare Workers to support both frontend pages and API routes? Is the setup different from React projects?
2 replies
BABetter Auth
Created by bkyerv on 4/9/2025 in #help
typescript not recognizing role field in astro locals with better auth
added a role field via additionalFields in auth.ts. At runtime, isAuthed.user from auth.api.getSession correctly includes role, but TypeScript doesn’t recognize it on Astro.locals.user. My env.d.ts uses import("better-auth").User, which lacks custom fields. Tried inferAdditionalFields<typeof auth>() on the client, but it didn’t help Astro’s types. Any advice on aligning the types properly?
5 replies
BABetter Auth
Created by bkyerv on 4/8/2025 in #help
what's the signature format for session cookies?
When examining a working session cookie created by Better Auth (__Secure-better-auth.session_token), I see it has a format like token.signature. What algorithm/process is used to create this signature? Is there a way to generate a valid cookie manually or is this only possible through Better Auth's internal APIs?
10 replies
BABetter Auth
Created by bkyerv on 4/8/2025 in #help
how to integrate non-oauth providers?
I'm implementing Telegram login which doesn't follow OAuth flow. After verifying the user's Telegram credentials and creating/finding the user in my database, what's the correct way to create a proper Better Auth session? I want to avoid false negatives when checking sessions in my middleware.
5 replies
BABetter Auth
Created by bkyerv on 4/7/2025 in #help
better-auth Session Not Recognized After Manual Creation in Telegram Callback
Telegram successfully authenticates, and my callback verifies the data. However, I'm manually creating the session record in the DB and setting the session cookie afterwards. Below how I'm doing it in my /api/auth/callback/telegram.ts. After this manual setup and redirecting to a protected route, my middleware check await auth.api.getSession(...) fails to recognize the session, causing a redirect back to /signin. My Question: Is manually inserting into the session table and setting the better-auth.session_token cookie like this the correct approach for integrating a custom callback (like Telegram's data-auth-url) with better-auth?
// 1. Manually Create Session Record in DB
const sessionToken = crypto.randomBytes(32).toString("hex");
await userDb.insert(session).values({
id: crypto.randomUUID(),
userId: userId, // Gotten from finding/creating user earlier
expiresAt: sessionExpiresAt,
token: sessionToken, // Store the generated token
createdAt: nowForSession,
updatedAt: nowForSession,
ipAddress: clientAddress,
userAgent: userAgent,
}).execute();

// 2. Manually Set Cookie using Astro's helper
cookies.set("better-auth.session_token", sessionToken, {
path: "/",
httpOnly: true,
secure: import.meta.env.PROD,
sameSite: "lax",
maxAge: SESSION_MAX_AGE // e.g., 30 days
});
// 1. Manually Create Session Record in DB
const sessionToken = crypto.randomBytes(32).toString("hex");
await userDb.insert(session).values({
id: crypto.randomUUID(),
userId: userId, // Gotten from finding/creating user earlier
expiresAt: sessionExpiresAt,
token: sessionToken, // Store the generated token
createdAt: nowForSession,
updatedAt: nowForSession,
ipAddress: clientAddress,
userAgent: userAgent,
}).execute();

// 2. Manually Set Cookie using Astro's helper
cookies.set("better-auth.session_token", sessionToken, {
path: "/",
httpOnly: true,
secure: import.meta.env.PROD,
sameSite: "lax",
maxAge: SESSION_MAX_AGE // e.g., 30 days
});
1 replies
CDCloudflare Developers
Created by bkyerv on 3/15/2025 in #general-help
transfer domain between Cloudflare accounts
I need to move a domain from one Cloudflare account to another. The domain is already on Cloudflare—I just want to transfer it to a different Cloudflare account. What’s the best way to do this?
3 replies
DTDrizzle Team
Created by bkyerv on 2/22/2025 in #help
Connection management with Drizzle
No description
3 replies
BABetter Auth
Created by bkyerv on 2/14/2025 in #help
TypeScript Error: ActionArgs not assignable to Request in better-auth handler
Following the docs at https://www.better-auth.com/docs/integrations/remix for setting up the API route handler, but getting a TypeScript error when passing the request object.
import { authClient } from "~/lib/auth-client";
import { type Route } from "../+types/root";
import { auth } from "~/lib/auth";
import { Form } from "react-router";

export async function action({ request }: { request: Route.ActionArgs }) {
return auth.handler(request);
}

export default function Signin() {
return (
<div className="pt-12 flex items-center justify-center">
<div className="p-12 border rounded-md space-y-4">
<p className="text-center">welcome back</p>
<Form action="" method="post">
<button className="border rounded-md px-2 py-1">
continue with google
</button>
</Form>
</div>
</div>
);
}
import { authClient } from "~/lib/auth-client";
import { type Route } from "../+types/root";
import { auth } from "~/lib/auth";
import { Form } from "react-router";

export async function action({ request }: { request: Route.ActionArgs }) {
return auth.handler(request);
}

export default function Signin() {
return (
<div className="pt-12 flex items-center justify-center">
<div className="p-12 border rounded-md space-y-4">
<p className="text-center">welcome back</p>
<Form action="" method="post">
<button className="border rounded-md px-2 py-1">
continue with google
</button>
</Form>
</div>
</div>
);
}
Error:
Argument of type 'ActionArgs' is not assignable to parameter of type 'Request'.
Type 'ActionArgs' is missing the following properties from type 'Request':
cache, credentials, destination, headers, and 18 more
Argument of type 'ActionArgs' is not assignable to parameter of type 'Request'.
Type 'ActionArgs' is missing the following properties from type 'Request':
cache, credentials, destination, headers, and 18 more
1 replies
BABetter Auth
Created by bkyerv on 2/14/2025 in #help
Google Sign-In Not Working with `authClient.signIn.social()`
I'm implementing Google authentication using better-auth with React. Here's my setup: 1. Client-side auth client:
import { createAuthClient } from "better-auth/react";
export const authClient = createAuthClient({
baseURL: "http://localhost:5173",
});
import { createAuthClient } from "better-auth/react";
export const authClient = createAuthClient({
baseURL: "http://localhost:5173",
});
2. Server-side auth configuration:
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";

export const auth = betterAuth({
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
},
},
database: drizzleAdapter(db, {
provider: "sqlite",
}),
});
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";

export const auth = betterAuth({
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
},
},
database: drizzleAdapter(db, {
provider: "sqlite",
}),
});
3. Sign-in component:
<button
onClick={async () =>
await authClient.signIn.social({
provider: "google",
callbackURL: "/dashboard",
errorCallbackURL: "/error",
disableRedirect: true,
})
}
>
continue with google
</button>
<button
onClick={async () =>
await authClient.signIn.social({
provider: "google",
callbackURL: "/dashboard",
errorCallbackURL: "/error",
disableRedirect: true,
})
}
>
continue with google
</button>
Issue: When I click the sign-in button, nothing seems to happen. I've configured my Google OAuth credentials and environment variables, but the authentication flow isn't starting. Questions: Am I missing any configuration steps? Is there a way to debug the authentication flow? Should I be handling the response from authClient.signIn.social() differently? Environment: better-auth (latest version) React TypeScript React Router
6 replies
CDCloudflare Developers
Created by bkyerv on 2/13/2025 in #workers-help
Best practices for customizing Worker entry point in Astro + Cloudflare Workers static assets setup
I'm working on an Astro project with Cloudflare Workers (static assets) integration, and I need to access Worker bindings (D1 database) in my API endpoints. Currently, my wrangler.json has "main": "./dist/_worker.js/index.js" which seems to be set up by Astro. I want to add custom Worker logic to handle API routes and access D1, but I'm unsure about the best/safest way to do this without breaking Astro's existing Worker setup. I see a few possible approaches: - Modify the main entry point in wrangler.json (but this seems risky) - Use Astro's middleware system somehow - Something else? My current wrangler.json:
{
"main": "./dist/_worker.js/index.js",
"compatibility_date": "2025-02-04",
"assets": {
"binding": "ASSETS",
"directory": "./dist"
},
"d1_databases": [
{
"binding": "DB",
"database_name": "users-dev",
"database_id": "..."
}
]
}
{
"main": "./dist/_worker.js/index.js",
"compatibility_date": "2025-02-04",
"assets": {
"binding": "ASSETS",
"directory": "./dist"
},
"d1_databases": [
{
"binding": "DB",
"database_name": "users-dev",
"database_id": "..."
}
]
}
What's the recommended way to add custom Worker logic while maintaining Astro's existing Worker setup? Any help would be appreciated! 🙏
2 replies
CDCloudflare Developers
Created by bkyerv on 1/13/2025 in #workers-help
deploying existing astro app using workers
is it possible to deploy an existing astro framework app using cloudflare workers for static assets? or does deploying with workers require the project to be initiated using npm run cloudflare@latest? i’m trying to understand if i can adapt an already built app for this setup. thanks!
4 replies
CDCloudflare Developers
Created by bkyerv on 1/11/2025 in #workers-help
Cloudflare Worker + Astro Deployment Issue
Running into an issue with deploying static assets in my Cloudflare Worker project using Astro. The deployment command (npm run deploy) that was working fine yesterday is now throwing this error:
const readdirp_1 = require("readdirp");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module
const readdirp_1 = require("readdirp");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module
Seems like there might be a dependency conflict with ESM/CommonJS modules. Has anyone run into this recently or knows a workaround? Any help appreciated!
6 replies
CDCloudflare Developers
Created by bkyerv on 1/10/2025 in #workers-help
React SSR on Cloudflare Workers fails due to missing MessageChannel API
Ran into an interesting issue deploying an Astro site using workers (not pages. instead serving static assets using worker): The React renderer fails with MessageChannel is not defined error when trying to do server-side rendering in Workers.
✘ [ERROR] Deployment failed!

Failed to publish your Function. Got error: Uncaught ReferenceError: MessageChannel is not defined
at renderers.mjs:6530:16 in requireReactDomServer_browser_production
at renderers.mjs:12527:8 in requireServer_browser
at renderers.mjs:12539:29
✘ [ERROR] Deployment failed!

Failed to publish your Function. Got error: Uncaught ReferenceError: MessageChannel is not defined
at renderers.mjs:6530:16 in requireReactDomServer_browser_production
at renderers.mjs:12527:8 in requireServer_browser
at renderers.mjs:12539:29
Has anyone found a clean workaround for this?
3 replies
CDCloudflare Developers
Created by bkyerv on 10/30/2024 in #workers-help
Cloudflare Workflows Binding Error in Astro Project
No description
5 replies
CDCloudflare Developers
Created by bkyerv on 10/30/2024 in #workers-help
Integrating Cloudflare Workflows with Astro
I'm trying to integrate the newly announced Cloudflare Workflows with an existing Astro project (not using the starter template) and running into some TypeScript issues. Issue 1: Module Resolution Getting error on import:
import { WorkflowEntrypoint, WorkflowStep, WorkflowEvent } from "cloudflare:workers";
// Error: Cannot find module 'cloudflare:workers' or its corresponding type declarations.ts
import { WorkflowEntrypoint, WorkflowStep, WorkflowEvent } from "cloudflare:workers";
// Error: Cannot find module 'cloudflare:workers' or its corresponding type declarations.ts
Issue 2: Type Arguments Example from docs throwing TS error:
const apiResponse = await step.do("some other step", async () => {
let resp = await fetch("https://api.cloudflare.com/client/v4/ips");
return await resp.json<any>(); // Error: Expected 0 type arguments, but got 1.ts(2558)
});
const apiResponse = await step.do("some other step", async () => {
let resp = await fetch("https://api.cloudflare.com/client/v4/ips");
return await resp.json<any>(); // Error: Expected 0 type arguments, but got 1.ts(2558)
});
Current setup
{
"dependencies": {
"@astrojs/check": "^0.9.4",
"@astrojs/cloudflare": "^11.2.0",
"@astrojs/node": "^8.3.4",
"@astrojs/tailwind": "^5.1.2",
"@cloudflare/workers-types": "^4.20241022.0",
"astro": "^4.16.7",
"tailwindcss": "^3.4.14",
"typescript": "^5.6.3"
}
}
{
"dependencies": {
"@astrojs/check": "^0.9.4",
"@astrojs/cloudflare": "^11.2.0",
"@astrojs/node": "^8.3.4",
"@astrojs/tailwind": "^5.1.2",
"@cloudflare/workers-types": "^4.20241022.0",
"astro": "^4.16.7",
"tailwindcss": "^3.4.14",
"typescript": "^5.6.3"
}
}
Questions: What's the correct way to set up Workflows in an existing Astro project? What should the folder structure look like? Are there any specific configuration steps needed for TypeScript to recognize the cloudflare:workers module? How do we properly type the json<T>() response? Any help or guidance would be greatly appreciated! 🙏
1 replies
CDCloudflare Developers
Created by bkyerv on 10/16/2024 in #pages-help
Need Help with Astro + Cloudflare + Turso DB Setup
Hey everyone, I’m running into an issue with my Astro app. Locally, everything works fine, but in production on Cloudflare, I’m getting a 401 Unauthorized error when trying to insert data into the database (db.insert(Waitlist_signups)). I’m using Turso for the database as per the documentation and have added the necessary environment variables (both the DB token and URL) in Cloudflare, but still facing this issue. Has anyone encountered something similar or know what could be causing the 401 error? Thanks in advance for any help!
4 replies
CDCloudflare Developers
Created by bkyerv on 10/15/2024 in #pages-help
Issue with Remix App Deployment on Cloudflare Pages - 404 Error After Successful Deploy
I’m having trouble deploying a simple Remix app. I created the app by running npm run remix@latest, pushed the local repo to GitHub, and connected it to Cloudflare Pages. I set up the deployment and picked the correct repo. The deployment is successful, but when I click the link, I’m getting a 404 error instead of the page being rendered. I followed the Pages documentation and pointed to the correct build/client folder. Any ideas on what could be wrong?
5 replies
CDCloudflare Developers
Created by bkyerv on 9/30/2024 in #general-help
Locating Worker file in static assets (Astro) server from worker
I'm working on a project using Astro as a framework for a Cloudflare Worker, but I'm a bit lost in the project structure. I used the npm create cloudflare@latest command to set up the project, which gave me what looks like a standard Astro project. My main questions are: - Where should I place the Worker code? Or has it already been set up by the Cloudflare package? - In general, where can I find the Worker-specific parts of this project? If anyone has experience with this setup, I'd really appreciate some guidance on navigating the project structure and identifying where these Cloudflare Worker elements fit in. Thanks in advance for any help!
2 replies
CDCloudflare Developers
Created by bkyerv on 9/11/2024 in #general-help
Cloudflared setup: Empty config.yml file - Manual creation or automatic generation?
Hey everyone, I'm trying to set up cloudflared but I'm hitting a snag. I'm getting an error saying my config file at /Users/by/.cloudflared/config.yml is empty. I'm not sure if I need to create this file manually or if there's a command that should generate it automatically. Has anyone dealt with this before? Any tips on how to properly populate the config file? Thanks in advance!
5 replies