Crypto not found

I'm running a Solid Start app using bun and sst, however I get this error in my console: ERROR crypto is not defined Better Auth I have absolutely no idea why this happening, i got it working for a moment, but it reappeared now.
23 Replies
bekacru
bekacru12mo ago
are you on latest?
Jackson Kasi
Jackson Kasi12mo ago
Hey @bekacru, I am getting this error now in Node 18 & 20. But this crypto issue does not appear if I run the server with Deno https://github.com/jacksonkasi1/better-auth-example
GitHub
GitHub - jacksonkasi1/better-auth-example
Contribute to jacksonkasi1/better-auth-example development by creating an account on GitHub.
No description
NotLuksus
NotLuksusOP12mo ago
yeah latest bun and latest better auth
bekacru
bekacru12mo ago
can you check if this is still the case on latest
NotLuksus
NotLuksusOP12mo ago
I still get the error but at a different place, before when clicking register without emai / password it just didnt respond and said crypto is missing, now I get invalid email, password is to short but when i enter normal credentials it gives the same error ERROR crypto is not defined Better Auth at Object.ke [as hash] (node_modules/better-auth/dist/index.js:1:823) at node_modules/better-auth/dist/index.js:83:1562 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async handle (node_modules/better-auth/node_modules/better-call/dist/index.js:374:17) at async a.<computed> (node_modules/better-auth/dist/index.js:83:5818) at async handler (node_modules/better-auth/node_modules/better-call/dist/index.js:588:26) at async handler (node_modules/better-auth/node_modules/better-call/dist/index.js:639:19) at async eval (/home/notluksus/dev/sodefa/graphrag-demo/node_modules/@solidjs/start/dist/server/handler.js:38:23) at async _callHandler (/home/notluksus/dev/sodefa/graphrag-demo/node_modules/h3/dist/index.mjs:1821:16) This is the stack trace
bekacru
bekacru12mo ago
could you try the it on next pnpm i better-auth@next
NotLuksus
NotLuksusOP12mo ago
yeah works Nvm still the error It somewhat worked with the previous version, there it created a user in the database but not account. Then I tried to register for that email again, it failed because the email exists, i remove the user. I registered again and now its broken
bekacru
bekacru12mo ago
is the error still crypto not found?
NotLuksus
NotLuksusOP12mo ago
yes also im using bun, probably shouldnt matter, just fyi This seems to be a solid start issue, when using the global crypto namespace it breaks
bekacru
bekacru12mo ago
Yeah got that. I’ve switched to the imported crypto module, so it should have been fixed. I’ll check later why it is still happening.
NotLuksus
NotLuksusOP12mo ago
Thank you, keep me posted please!
bekacru
bekacru12mo ago
check for me if it's fixed on next if not please send me the stack trace
NotLuksus
NotLuksusOP12mo ago
works :) Ok turns out that now registering and so on works, however the password isn't set Password not found { email: 'XXX' }
NotLuksus
NotLuksusOP12mo ago
The account in drizzle also has an empty password column
No description
bekacru
bekacru12mo ago
hmm can you pass custom verify and hash password you can use Bun's builtin password hasher in the auth config emailAndPassword.password
NotLuksus
NotLuksusOP12mo ago
one sec i'm even more confused now, it turns out that when using sst, even if im in a bun monorepo / project, it runs node So since it isnt running bun i used bcrypt:
async hash(password) {
return await bcrypt.hash(password, 10);
},
async verify(password, hash) {
return await bcrypt.compare(password, hash);
},
async hash(password) {
return await bcrypt.hash(password, 10);
},
async verify(password, hash) {
return await bcrypt.compare(password, hash);
},
Password field is stay empty
bekacru
bekacru12mo ago
No idea. If possible, create a public repo so I can reproduce it on my end. does the session get created?
NotLuksus
NotLuksusOP12mo ago
yeah it does yeah let me try to get a reproduction
NotLuksus
NotLuksusOP12mo ago
GitHub
GitHub - NotLuksus/better-auth-repro
Contribute to NotLuksus/better-auth-repro development by creating an account on GitHub.
NotLuksus
NotLuksusOP12mo ago
pnpm install, set env, start a local postgres docker run --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres, pnpm dev inside the web package, signup, check account using drizzle studio, account password should be empty, signout, try to sign back in again, no password found error I removed the sst part for simplicity as it doesnt really add much to the case here anyway
bekacru
bekacru12mo ago
thanks. I'll take a look. I just found the issue: the password field was named passwordHash in your Drizzle schema. It doesn't matter what it maps to in the database, Drizzle will ignore the password field.
NotLuksus
NotLuksusOP12mo ago
omg, thank you, what a stupid mistake!
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?