Cannot read properties of undefined (reading 'accountId')

I can't seem to figure out what this issue is. Steps: 1. Create new account with Google social provider 2. Sign out of the account and refresh 3. Try to sign in again 4. It goes to url http://localhost:3000/api/auth/callback/google?state=xyz&code=xyz&scope=email+profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&authuser=0&prompt=none where it says This page isn’t working localhost is currently unable to handle this request. HTTP ERROR 500 5. I click reload and it takes me to the better auth error page which states We encountered an issue while processing your request. Please try again or contact the application owner if the problem persists. and Error Code: please_restart_the_process 6. Restart from step 3 In my server logs I see: [Auth Database Hooks]: Before account update - start SERVER_ERROR: [TypeError: Cannot read properties of undefined (reading 'accountId')] [Auth Database Hooks]: Before account update - end Not sure where it's happening outside of that. If it helps, I changed all camelCase names to snake_case
1 Reply
DN_Dev
DN_DevOP3mo ago
I was able to fix it. I wrapped all my database hooks but assumed that returning nothing would allow the middleware to continue as normal. I had to explicitly return { data: account } for e.g. in the before hooks. I feel like the docs didn't make it clear 😅 It says: Behavior: If the hook returns false, the operation will be aborted. And If it returns a data object, it'll replace the original payload. The TS return types also allow for boolean, void and { data: Account } - I assumed returning true or void would just let it continue with the normal payload. Anyway, works great now

Did you find this page helpful?