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
@admin
I'm waiting for solution ???
@bekacru
Do you have an error message?
@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
this means the user you're using made emails private and can't be requested.
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
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.
Okay check and let me know about what to do and i am using google one not github
actually that can't be the issue. My email is private.
can you see if the same thing happens on our demo
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 ?
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?
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 ..
that error should only show for github. Google should work.
I'm getting this bro don't know why 😭
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.
I tried to debug for 4 hours
how are you calling the social endpoint?
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.
Do you have a second google account which you can test?
Ya I have
I should try from another account
@Ping
Yes, please try.
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.
yeah we're working on optimizing the ts server performance. bog imporvements soon!
Okay 👍