BA
Better Auth•5d ago
stewie

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
Mukund
Mukund•4d ago
Hey, how can I help you? Do you want to know complete setup or stuck in some part?
The Untraceable
The Untraceable•4d ago
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
stewie
stewieOP•4d ago
i get stuck in some part and then the whole thing gets disrupted
stewie
stewieOP•4d ago
No description
No description
No description
stewie
stewieOP•4d ago
@Mukund you there?
Mukund
Mukund•4d ago
Yes
Nelson
Nelson•4d ago
What errors are you getting? There is no callbacks field in BetterAuth.
Mukund
Mukund•4d ago
@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.
Mukund
Mukund•4d ago
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)
stewie
stewieOP•4d ago
bruhh it still doesnt work 😭
stewie
stewieOP•4d ago
No description
stewie
stewieOP•4d ago
i can share my screen ig you wanna see code @Nelson
Nelson
Nelson•4d ago
Show the error logs in terminal
stewie
stewieOP•4d ago
○ 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
Nelson
Nelson•4d ago
Check your database to see if those tables have really been migrated.
stewie
stewieOP•4d ago
yeah
No description
Nelson
Nelson•4d ago
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
stewie
stewieOP•4d ago
now only db part is left like i had my schema and then added according to better-auth so maybe that caused error
Nelson
Nelson•4d ago
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#verification
stewie
stewieOP•4d ago
It is working now thanks a lot @Mukund and also @Nelson

Did you find this page helpful?