help
i am using better-auth first time and getting confused by the docs i wanna implement auth in my next app like i wanna have a signup and signout button and auth middleware or something to prevent access to routes
20 Replies
Hey, how can I help you?
Do you want to know complete setup or stuck in some part?
Wouldn't recommend middleware, they run on each request. For signing up you use authClient.signUp.email, authClient.signIn.email for signing in, and authClient.signOut for signing out.
Personally I run auth checks per page via a requireSession helper that checks for session, if not found it redirects
i get stuck in some part and then the whole thing gets disrupted



@Mukund you there?
Yes
What errors are you getting? There is no callbacks field in BetterAuth.
@stewie Here: https://github.com/mukund1606/better-auth-google-example
I have created a demo repository showing how you can implement better auth in nextjs with google social provider
GitHub
GitHub - mukund1606/better-auth-google-example
Contribute to mukund1606/better-auth-google-example development by creating an account on GitHub.
From what I can see your auth config is wrong
instead of adapter it should be database,
instead of providers it should be socialProviders
and there is no callbacks property (there are hooks and databaseHooks)
bruhh it still doesnt work ðŸ˜

i can share my screen ig you wanna see code
@Nelson
Show the error logs in terminal
â—‹ Compiling /api/auth/[...better-auth] ...
✓ Compiled /api/auth/[...better-auth] in 4.9s
SERVER_ERROR: [Error [BetterAuthError]: Model verification does not exist in the database. If you haven't generated the Prisma client, you need to run 'npx prisma generate'] {
cause: undefined
}
POST /api/auth/sign-in/social 500 in 11408ms
but i have done npx prisma genrate already
Check your database to see if those tables have really been migrated.
yeah

I think you are migrating from NextAuth/Authjs to BetterAuth.
If so, please read:
https://www.better-auth.com/docs/guides/next-auth-migration-guide
If not, you may check out since you're using custom table names/field names:
https://www.better-auth.com/docs/concepts/database#custom-tables
now only db part is left like i had my schema and then added according to better-auth so maybe that caused error
I'm not sure what your current
auth.ts
and auth-client.ts
look like, but, as Mukund and I mentioned, your configuration is set up incorrectly.
- adapter
should be database
- providers
should be socialProviders
- no callbacks
(we have hooks
and databaseHooks
- baseURL
in auth-client.ts
should be http://localhost:3000
in your case (or you can remove it since you're using the same domain).
Also, you have a VerificationToken
table, which should be verification
, but you may want to customize it.
https://www.better-auth.com/docs/concepts/database#verificationIt is working now thanks a lot @Mukund and also @Nelson