SERVER_ERROR: Error: hex string expected, got undefined

So i started migrating from clerk to better auth. the docs are amazing. i love everything about better auth. so i run the migration script. added the accounts and done everything. then i tried logging in from my expo app and got the following error SERVER_ERROR: Error: hex string expected, got undefined at hexToBytes (file:///Users/mac/Desktop/work/GoGain/GoGain-backend/node_modules/@noble/hashes/esm/utils.js:141:15) at Object.verifyPassword [as verify] (file:///Users/mac/Desktop/work/GoGain/GoGain-backend/node_modules/better-auth/dist/shared/better-auth.OT3XFeFk.mjs:45:39) at async file:///Users/mac/Desktop/work/GoGain/GoGain-backend/node_modules/better-auth/dist/shared/better-auth.cM0Fc3LZ.mjs:1738:27 at async internalHandler (file:///Users/mac/Desktop/work/GoGain/GoGain-backend/node_modules/better-call/dist/index.js:576:22) at async api.<computed> (file:///Users/mac/Desktop/work/GoGain/GoGain-backend/node_modules/better-auth/dist/api/index.mjs:516:22) at async processRequest (file:///Users/mac/Desktop/work/GoGain/GoGain-backend/node_modules/better-call/dist/index.js:4881:24) at async handler (file:///Users/mac/Desktop/work/GoGain/GoGain-backend/node_modules/better-call/dist/index.js:4901:19) at async file:///Users/mac/Desktop/work/GoGain/GoGain-backend/node_modules/better-call/dist/node.js:138:22 here's an example of one line of password from my csv user_2q8MgHHfYJitwcfLo7MAe2X0rLU,zak,zak,,guest@gmail.com,,guest@gmail.com,,,,,$2a$10$0VHVVjA5W4UaMA94WjahseL4NYHseXRQS8z6fC1/4hgUij.QUCiOu,bcrypt rest assured these are dev dummy users nothing critical that's why i shared that. can anyone help? why is that happening?
2 Replies
Jerematix
Jerematix4mo ago
Hi @zakisb97 I'm currently facing the same issue, locally with dev server it works, but when building and deploying to server it doesn't work. At least for my issue, I found that it seems to have something to do with crypto operations part, when I have a wrong email, it gets blocked before and I get a 401. I'm running it on a docker image with bun. For me the error looks like this: SERVER_ERROR: Error: hex string expected, got undefined at <anonymous> (.next/server/chunks/249.js:1:45004) at <anonymous> (.next/server/chunks/249.js:1:45416) at processTicksAndRejections (null) Have you found a fix or any other information so far?
zakisb97
zakisb97OP3mo ago
hello sorry for the late reponse yes i found the error and the problem i just had to add this
emailAndPassword: {
enabled: true, // Enable authentication using email and password.
// requireEmailAlreadyVerified: true, // guarantees “step 2” happened
password: {
hash: async (password) => {
return await bcrypt.hash(password, 10);
},
verify: async ({ password, hash }) => {
return await bcrypt.compare(password, hash);
},
},
},
emailAndPassword: {
enabled: true, // Enable authentication using email and password.
// requireEmailAlreadyVerified: true, // guarantees “step 2” happened
password: {
hash: async (password) => {
return await bcrypt.hash(password, 10);
},
verify: async ({ password, hash }) => {
return await bcrypt.compare(password, hash);
},
},
},
to my auth config ( the password object)

Did you find this page helpful?