Issue with Google Auth

I am setting up thing as they are in docs but i am getting error when i am doing signup or signin using google i am not able to solve it, help me with this please :- const handleGoogleSignIn = async () => { try { const data = await authClient.signIn.social({ provider: "google" }) if (data.error) { throw new Error(data.error.message); } } catch (error: unknown) { console.error("Error while loggingin through Google", error); toast({ title: "Error", description: (error as Error).message || "An error occurred during sign-up.", variant: "destructive", }); } }; socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, } }, in auth.ts POST /api/auth/sign-in/social?currentURL=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Fsign-in 400 in 341ms getting this how to fix help me
24 Replies
Tarun kumar
Tarun kumarOP4w ago
@admin I'm waiting for solution ??? @bekacru
Ping
Ping4w ago
Do you have an error message?
Tarun kumar
Tarun kumarOP4w ago
@Ping I have when so when i try to click on the button signup or login with google in the console it shows this :- POST /api/auth/sign-in/social?currentURL=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Fsign-up 400 in 764ms and in the network tab i see the request then in response it shows this error : {"error":"Email is required"} I tried with same client id and secret in next auth it worked in a single time then what is the issue here. if you have a solution do let me know.. @b @bekacru
bekacru
bekacru4w ago
this means the user you're using made emails private and can't be requested.
Tarun kumar
Tarun kumarOP4w ago
what does that means i tried with next auth it was working fine with that I tried to update too better auth but didn't worked then also can you tell me the solution to this what can i do to fix this issue
bekacru
bekacru4w ago
go to github email setting and uncheck keep my email addresses private. But it should have wokred even with private email addresses. I'll check.
Tarun kumar
Tarun kumarOP4w ago
Okay check and let me know about what to do and i am using google one not github
bekacru
bekacru4w ago
actually that can't be the issue. My email is private. can you see if the same thing happens on our demo
bekacru
bekacru4w ago
Better Auth
Better Auth
The most comprehensive authentication library for typescript
Tarun kumar
Tarun kumarOP4w ago
I tried to explore this demo/next.js but from there also it didn't worked So you mean to say error is from your side that your email id is private which is somehow related in working of this whole google auth. is it so no on demo it is working fine i was able to login with google it is opening that accounts,google.com window but not on my application ?? i just checked @bekacru Did you got the solution for this ?
bekacru
bekacru4w ago
have you tried to login with github with the demo and it didn't work? google should work. what is the error with google in your app?
Tarun kumar
Tarun kumarOP4w ago
What I have sent you it is saying email is required when I'm requesting on api/auth/signin/social using authclient it is showing this error. This I tried same client id and secret with next auth it was working perfectly not here I don't know why I have written exact code as given in the docs still then I tried to copy code from github repo of this better auth demo/nextjs then also it is showing same error I can't understand why ..
bekacru
bekacru4w ago
that error should only show for github. Google should work.
Tarun kumar
Tarun kumarOP4w ago
I'm getting this bro don't know why 😭
bekacru
bekacru4w ago
we're not doing anything differnt from next auth. I can't tell what is the issue, but if you can go to the demo site I sent you and try to login with google.
Tarun kumar
Tarun kumarOP4w ago
I tried to debug for 4 hours
bekacru
bekacru4w ago
how are you calling the social endpoint?
Tarun kumar
Tarun kumarOP4w ago
Await authClient.signIn.social({ provider: "google", }) This I tried on it it is working for me also but the same code I'm running it is not working I can't understand why As I said I have tried from docs then from the better auth github repo but from both I'm getting same error 400 it is saying missing parameters and in the message email is required.
Ping
Ping4w ago
Do you have a second google account which you can test?
Tarun kumar
Tarun kumarOP4w ago
Ya I have I should try from another account @Ping
Ping
Ping4w ago
Yes, please try.
Tarun kumar
Tarun kumarOP4w ago
Will see and tell you guys tomorrow if it solves the problem but try to good for a solution if possible like I'm doing same thing only as in docs but it is giving error. Thank you for the support Though you didn't replied fast but I understand you may be busy but I had requirements too so that's why I was panicking so if I was rude in any way sorry for that and thank you I love this library @bekacru that's I'm using it even though it is working in next auth that's why it's a amazing product. 👏 @bekacru Please review and let me know what to do @bekacru I got it fixed bro it was my mistake i was using custom checks in the api/auth/[...auth]/route.ts and it was working for email pass login but not for social logins i had to change the code a bit but it is working now It took me a day to understand this error 😩 @bekacru I have one suggestion i wanted to tell you i think you should work on this part also that when ever i install the library my editor becomes too slow like "detecting errors" means when we do syntax error or typescript error it takes time to highlight that and these stuff and when i remove it everything becomes stable i think you should see to this and ways for fixing this, then it will be more better as performance is priority thing right.
bekacru
bekacru4w ago
yeah we're working on optimizing the ts server performance. bog imporvements soon!
Tarun kumar
Tarun kumarOP4w ago
Okay 👍

Did you find this page helpful?