36 Replies
It creates no cookie, no session, nothing. Why is it incapable of giving me a useful error?
Can you share your auth.ts file
This is for a new account, a sign up ? First time connect?
signIn.social should be redirecting you to GitHub to sign into your GitHub account, then from there redirecting you back to /api/auth/callback/github after you sign in
What do you have your GitHub redirect_uri configured to? It your GitHub.com developer settings for your oauth app
As for debugLogs, you have it set to true in your drizzleAdapter which enables debug logs for Drizzle queries, but you can additionally pass debugLogs to betterAuth({ }) (the root options)
Like this
Sorry actually it's logger
Well I'm trying to sign in with github OAuth, but it's not sending me to github. at all, it just shows the logs from my first post
Can you show me the code you are using to sign in with GitHub?
Are you possibly doing it in a server action?
my nextjs app runs on 4200
If you aren't getting redirect to GitHub this would be a client side issue I think, need to see the code where you are invoking signIn.social
I see the API is returning a 200 for sign-in/social for you, the authClient should handle redirecting you to GitHub
Can you show me the code for your Sign in with GitHub button and the function it calls
is the signInProvider a custom provider you made?
a ContextProvider it looks like from here
yeah
You shouldn't need to try { catch } the signIn.social, since you aren't passing fetchOptions: {throw: true} to it
So you can remove that try catch block
I see what is happening though
You are calling window.location.href = "callback" yourself, get rid of that
your window.location.href there is overriding the authClient's
So it is going directly to your callbackURL which is /meals instead of GitHub
You're not seeing the logs in the API because this is a client side issue here, and also there are no errors from Better Auth which is why it isn't logging any, here I will show you how to fix
This should work
yeah it works now ty
You pass your callbackURL to social({}) and it will redirect you there after sign up
sure thing
Thank you so much, I would've never found this myself tbh
since there wasn't any error to go on really
No prob lucky I opened my laptop just now heh. But yea, the authClient.signIn.social method will handle redirects for you automatically
Yeah I missed that, but thanks again, I was pulling my hair out.
Is there anywhere I can see the schema's better auth expects? Because it generated this
At least, that's what I think, but now I'm getting
Oh.. you're using GitHub sign in + username plugin, interesting
I think GitHub is trying to sign up a user with null as the username
Try adding .notNull() to username
wait
no dont do that one sec
No the issue is the unique constraint, I think that forces it to be not null, since otherwise if you'd have multiple null records, that would make it not unique
Yea one sec
I don't know if username plugin is compatible with Github sign in out of the box. Cause in this case you want it to be null
I think you need to generate a random username for them
Yeah maybe infer it from their email or something
and populate it in the before hook for the database
One sec
can you paste your full schema
That unique() constraint should allow null
Is it possible your database schema actually has NOT NULL applied to username
Or some other relation is checking username
So yea I would say to run the database migrations again, paste your full schema to me, then do a drizzle-kit pull and paste the schema it pulls down separately
wait you're right, when I reran the migration the null constraint disappeared, sorry!
perfect
one last thing, in the signInProvider, I also do a router.push(callbackURL);
is that also a bad idea?
nah you don't need to do that for oauth
it'll automatically redirect to callbackURL you pass to signIn.social
you can do that router push after an email/pass sign in tho
I'm running into an issue where the client sends a token like xxxxxxxxxxx(dot)xxxxxxxxxxxxx but the sessions table only has the token part before the dot, this leads to 401 errors, any idea why the client sends xxxxxxxxxxx(dot)xxxxxxxxxxxxx?
I'm not quite sure
whats the feature that's not working
The client sends a token that includes an additional encoded segment (e.g., abc123.xyz789), while the database stores only the base part (e.g., abc123). This causes the server to reject the token as invalid, resulting in a 401 Unauthorized error.
That's how to cookie is saved in the browser, abc123.xyz789, but when I look in the db the session token column only contains abc123
What is sending this token
Like what feature isn't working
Sign in? sign up? email verification?
social sign in?
Or nothing
Better auth sets a cookie with token abc123.xyz789 in the browser. But in the sessions table the token only consists of abc123.
So when I send a cookie to the backend using withCredentials using axios or something and compare it with the token in the sessions table they don't match up
Yea I have no idea I'm not using axios at all and IDK why it would be storing it like that with your setup
Try not using a cookie prefix
But that has nothing to do with axios? It's literally how better-auth inserts the cookie into the browser.
If I use cookies() it retrieves abc123.xyz789 from the browser, and that's how I can see it in the developer tools > application > cookies as well
IDK I would make a separate post about this cause I'm not sure why it's doing that for you. Maybe someone else will see it, include your auth.ts and any related functions in that post
Okay thanks bud, I asked around in the general, but I'll make a new help post. Appreciate the help.