onboarding new users

@Better Auth I'm using social logins/sign ups (google and github) and passwordless otp for email signups in my next js app. if a user sign ups using google / github we can assume email is verified. And if new user successfully verifies otp token during sign in, we create session and redirect to onboarding route. how do i differentiate new users from old users during sign in. what is the auth configuration to achieve this?
2 Replies
Better Auth
Better Auth4w ago
You have a couple of options to differentiate new from returning users based on your chosen auth flows: • For social logins (Google/GitHub) you can leverage the built‐in option on the client API. When calling the social sign‑in method, you can provide a new user callback URL (e.g. newUserCallbackURL) so that if the user is signing in for the first time they get redirected to your onboarding route. For example:
await authClient.signIn.social({
provider: "google",
callbackURL: "/dashboard", // for returning users
newUserCallbackURL: "/onboarding", // for new users
disableRedirect: false,
});
await authClient.signIn.social({
provider: "google",
callbackURL: "/dashboard", // for returning users
newUserCallbackURL: "/onboarding", // for new users
disableRedirect: false,
});
This way, Better Auth automatically distinguishes new social accounts (whose email is already verified) and redirects them accordingly [4]. • For passwordless OTP flows using email, it’s best to keep new user registration separate from sign‑ins. In the OTP plugin you can add a sign‑up method (like authClient.signUp.emailOtp as suggested in previous feature requests [6]) so that new users who verify the OTP become registered and then you can redirect them to the onboarding route. The returning users will use authClient.signIn.emailOtp. If you’re already auto‑signing in users after OTP verification, then in your onSuccess callback you could check if this is their first login (for example by checking if extra profile details exist or using a flag in the session) and then redirect accordingly. In summary, by using separate endpoints or callbacks—specifically by setting the newUserCallbackURL for social sign‑in and creating distinct OTP endpoints for sign‑up and sign‑in—you can handle new versus returning users as needed. This approach aligns with the evolving recommendations in Better Auth’s documentation and feature requests
GitHub
better-auth/better-auth
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
Better Auth
Better Auth4w ago
GitHub
better-auth/better-auth
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
GitHub
better-auth/better-auth
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
Basic Usage | Better Auth
Getting started with Better Auth
GitHub
Sign up users without setting a password · Issue #1433 · better-a...
Is this suited for github? Yes, this is suited for github Is your feature request related to a problem? Please describe. I want to go passwordless using email OTP but let users sign up using a sign...

Did you find this page helpful?