ProStack includes a pre-built authentication system that supports both email/password authentication and social login options using BetterAuth.

What is BetterAuth?

BetterAuth is a comprehensive authentication solution that provides secure, customizable authentication for modern web applications. It offers features like:

  • Email/password authentication
  • Social logins
  • Email verification
  • Password reset
  • Multi-factor authentication
  • Team/organization management
  • Role-based access control

Authentication Components

ProStack provides ready-to-use authentication components:

Sign In Form

import SignInForm from "@/app/(app)/auth/components/sign-in-form";

export default function SignInPage() {
    return (
        <div>
            <h1>Sign In</h1>
            <SignInForm callbackURL="/dashboard" />
        </div>
    );
}

Sign Up Form

import SignUpForm from "@/app/(app)/auth/components/sign-up-form";

export default function SignUpPage() {
    return (
        <div>
            <h1>Create an Account</h1>
            <SignUpForm callbackURL="/dashboard" />
        </div>
    );
}

OAuth Buttons

import OAuthButtons from "@/app/(app)/auth/components/oauth-buttons";

export default function SocialLoginSection() {
    return (
        <div>
            <OAuthButtons callbackURL="/dashboard" />
        </div>
    );
}

Authentication Flow

  1. Sign Up: User creates an account with email/password or social login
  2. Email Verification: If enabled, user verifies their email address
  3. Sign In: User signs in with credentials or social provider
  4. Session Management: User remains authenticated for the duration of their session
  5. Sign Out: User signs out, ending their session

Customizing Authentication

You can customize the authentication system through configuration in lib/auth/index.ts:

export const auth = betterAuth({
  database: prismaAdapter(db, {
    provider: "postgresql",
  }),
  emailAndPassword: {
    enabled: true,
    autoSignIn: true,
    minPasswordLength: 6,
    resetPasswordTokenExpiresIn: siteConfig.auth.resetPasswordTokenExpiresIn.ms,
    sendResetPassword: async (props) => {
      if (isProd) await sendResetPasswordEmail(props);
      console.log("Sending reset password email", props);
    },
  },
  emailVerification: {
    sendOnSignUp: siteConfig.auth.emailVerification.enabled,
    autoSignInAfterVerification: true,
    sendEmailVerification: async (props) => {
      if (isProd) await sendVerificationEmail(props);
      console.log("Sending verification email", props);
    },
  },
  // Additional configuration options...
});

You can extend the auth config or visit the BetterAuth docs for more information.

Next Steps