-
Notifications
You must be signed in to change notification settings - Fork 45
[BUG] Windows build fails with Middleware and throws error without Middleware using better-auth
#494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
better-auth
better-auth
After upgrading to
Preview script (on Windows/WSL) with middleware still throws the same error, but without middleware still builds and now
Update:
|
Had a similar issue, only way I was able to resolve it was to setup WSL and dev from there. |
Hi @AimanHakeem, in my case working on a Linux machine solved this issue, as I was not able to get it to work via WSL on Windows. Should also work on Mac since it is Unix-based. Also to leave an update I managed to get the local preview working and solved the: the problem was in my import { drizzle } from 'drizzle-orm/d1';
import { getCloudflareContext } from '@opennextjs/cloudflare';
async function initDb() {
const { env } = await getCloudflareContext({ async: true });
if (!env.DB) {
throw new Error('DB is not defined in the environment variables');
}
return drizzle(env.DB, {
logger: true,
casing: 'snake_case',
});
}
export const db = await initDb(); https://github.com/aleksa-codes/next-better-auth-drizzle-d1/blob/main/src/db/index.ts |
I solved my errors and maintainers seem to be aware of Windows issues, so I think the issue can be closed. Thanks 🙂 As a long time Cloudflare customer I can say that the experience here and on the Discord server has been pretty bad to say the least. The communication has been very strict and even passive aggressive at some point, while I was nothing but polite and professional. Not sure if it is related to my lack of experience, AI avatar or just frustration coming from working overtime. I will stick to "just reading the docs 🙂". |
Describe the bug
I am trying to build and deploy a Next.js app using Drizzle, Cloudflare D1, better-auth and OpenNext. After digging deep to get this to work on the local development environment when running
yarn dev
(next dev
) works as expected, I can sign up and sign in and the middleware redirects.yarn preview
(opennextjs-cloudflare && wrangler dev --port 3000
) with the middleware, this is what I get, both on Windows and Windows using WSL:The main files that got me to this point, since I already faced some issues before like
this.client.prepare is not a function
mentioned onbetter-auth
Discord server, are:drizzle.config.ts
/src/db/index.ts
Compared to #483 (comment) that solved other similar issue I am not specifying node runtime in the middleware and same as the PR mentioned in that comment https://github.com/serban-mihai/opennext-better-auth/pull/1/files I am using:
import { getSessionCookie } from "better-auth/cookies";
in the middleware.Everything else is based on the working project I already have that is using Supabase and deployed to Vercel, with of course things like schema and everything else adapted to use D1 (SQLite) instead of Postgres.
Steps to reproduce
Minimum Reproduction
git clone [email protected]:aleksa-codes/next-better-auth-drizzle-d1.git
yarn install
ornpm install
src/db/migrations
run:yarn db:migrate:local
ornpm run db:migrate:local
.dev.vars
and.env.local
based on the examples (RESEND_API_KEY
is not needed)yarn dev
ornpm run dev
and try to register and after sign in, it should work as on my machineyarn preview
ornpm run preview
script.X [ERROR] Could not resolve "D:Projects\next-better-auth-drizzle-d1.nextserveredge-runtime-webpack.js"
etc.yarn preview
ornpm run preview
again.✘ [ERROR] ⨯ TypeError: Cannot read properties of undefined (reading 'definition')
Expected behavior
The app should build and the middleware should redirect you to
/signin
if you try to access/protected
whenever an auth session cookie is missing from the client storage.With and without the middleware the user should be able to register or login, similar to when the app is being ran using
next dev
.The local dev environment works fine using
next dev
, the preview usingopennextjs-cloudflare && wrangler dev --port 3000
is not. I have not yet tested production as I cannot get the local preview to work.@opennextjs/cloudflare version
0.5.12
Wrangler version
4.4.0
next info output
Additional context
The app uses Resend for email auth verification, but those parts of the code in
src/lib/auth.ts
have been commented out for easier testing, so theRESEND_API_KEY
is not required. I left the comment indev.vars.example
andenv.local.example
on how to generate if you needBETTER_AUTH_SECRET
.One thing that I am aware of and whoever reads this should keep in mind that I am as I already mentioned on the Discord server fairly new to using D1 and OpenNext for deploying on the Cloudflare Workers, I have used Cloudflare pages before for Next.js and deployed some Astro sites. I am saying this because for example I cannot understand the difference between
.dev.vars
and.env
yet and when is which one used, for example in mysrc/db/index.ts
, and if for example Preview is still considered development environment or not in this case, and things of that nature.Hope I wrote the issue good enough, gave my best shot to describe things.
The text was updated successfully, but these errors were encountered: