SyntaxError: "[object Object]" is not valid JSON on Google oauth callback
I'm trying to setup google oauth login and I'm receiving a strange error when the provider calls the callback URL. What I get in my server logs (I've added some logging in the library code):
the library code at the top of the stack is this function:
when I remove the JSON.parse call in that function I am able to complete the oauth sign in sucessfully.
Info about my environment:
better-auth 1.2.8 (had the same issue on 1.2.7 and tried upgrading)
hono 4.7.8
Is this a bug in the library or in my setup? Confused how the library expects a json string there but its already an object. Thanks in advance!
Solution:Jump to solution
Sorry, this was a problem on my side. I had the kysely plugin
ParseJSONResultsPlugin
enabled on the adapter5 Replies
auth config:
the callsite:
Solution
Sorry, this was a problem on my side. I had the kysely plugin
ParseJSONResultsPlugin
enabled on the adapter@Nick How did you end up dealing with this? Not having
ParseJSONResultsPlugin
will cause all sorts of issue with non-Better Auth queries, but leaving it in causes the "[object Object]"
issue.@andreasb My app didn't need ParseJSONResultsPlugin so I just removed it, I added it accidentally while migrating from supabase-js to kysely for a SSR app. Sorry that's not a great answer, maybe you could consider removing it and manually doing the JSON parsing yourself with a library like zod
Another idea could be to create a different db adapter for better-auth than your primary app
@Nick Thank you! Both very good suggestions, very much appreciated! I also see that ParseJSONResultsPlugin can be added on a per-query basis, but the dual db adapter approach must be tried, sounds a lot easier.
For future reference, ended up with a variant of Nick's suggestion:
Had no idea
withoutPlugins()
was a thing, solved it immediately!