email verification token not storing in table
For whatever reason when a new user signs up on my application, the email verification token sent to the user is not being stored in the database. If a user does password reset it stores this token just fine. I am not sure when or if it ever worked properly but I am certain that the table is hooked up correct as there are other better-auth endpoints that work as intended.
I can provide any code needed to fix this.
Solution:Jump to solution
@Sean I just opened pull request https://github.com/better-auth/better-auth/pull/3912 that change that behavior and introduce displayUsernameValidator that is disconnected of usernameValidator
GitHub
fix(username): remove normalize transform for displayUsername by os...
fix(username): remove normalize transform for displayUsername
feat(username): add displayUsernameValidator
This pull request restores the expected behavior of the username plugin.
Before:
It was no...
14 Replies
I am too facing the same issue. Using
"better-auth": "^1.3.4"
.I’m glad to see I’m not the only one. I’m on 1.2.12
@Krishna B they may have switched to a stateless approach in 1.2 at some point
Hey, mind sharing your auth config?
absolutely
let me know if oyu need more than this snippet. it wont let me send the full config in 1 message
Yeah it should send as a file, that would be better, thanks
In the drizzle adapter options, there should be a
debugLogs
option, enable that and run through the flow again, then try to spot what occurs when it attempts to add a value to DB for the verification table.https://github.com/better-auth/better-auth/blob/721f983b12abaa6d57285099c1a9c5826399861c/packages/better-auth/src/api/routes/email-verification.ts#L306C3-L306C40
Seems as if the verification token is generated using JWT.
GitHub
better-auth/packages/better-auth/src/api/routes/email-verification....
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
sorry it took so long, when I generate a new user it created models for account and user but not for the token tables
Also still haven't figure out where/why my displayUsername keeps being normalized as well. It seems that its fine until it hits the drizzle adapter then its all lowercased when its received
the username is particularly weird,
this snippets console.log shows the displayname with capitalization but when it hits the actual better-auth api it normalizes it. I don't believe this has always occured as I have some users with unnormalized names
Im not sure if it was when I updated better-auth with nuxt4's upgrade a month ago
I tried upgrading to 1.3.4 and both issues still occur
it should still store this token in the database no?
I guess no where in sendVerificationEmailFn does it store a token like it does in password-reset.ts which was generating tokens into the db as expected
thats interesting that they store it for update-user and password-reset but not email-verification. I guess this is my code is technically working as intended then? I need to make a custom JWT hook then to make it more secure or atleast encrypt the email on verification.
I see that in the username schema on better-auth it seems to be normalizing the display username. Is there a way to disable this or edit it in the auth config?
You can pass the normalizer config straight in the username plugin config
I only want to unnormalize the displayUsername. I'd like to keep usernames normalized is the issue
Solution
@Sean I just opened pull request https://github.com/better-auth/better-auth/pull/3912 that change that behavior and introduce displayUsernameValidator that is disconnected of usernameValidator
GitHub
fix(username): remove normalize transform for displayUsername by os...
fix(username): remove normalize transform for displayUsername
feat(username): add displayUsernameValidator
This pull request restores the expected behavior of the username plugin.
Before:
It was no...
@Sean @Ping So, in conclusion, when a user registers, will a verification code be generated in the database or not? I also tried it, and when registering, it didn't add anything to the verification table. However, the verification code sent can verify the user.
It never updates, i need to look into the source code and find why. I wonder if it’s either a bug or the intended use.
I’d love to be able to look up tokens to verify them rather than the current use case of just sending a jwt token with their email. Doesn’t seem secure