Authentication is a core part of any SaaS application. ShipNowKit uses better-auth to handle authentication and provides all necessary UI components for authentication flows.
Authentication Methods
ShipNowKit supports multiple authentication methods:
- Email/Password Login: Users can register and sign in using email and password
- Magic Link: Send a magic link via email for passwordless login
- OAuth Social Login: Support for third-party login with Google, GitHub, Discord, Facebook, Twitter, and more
Database Models
Authentication-related database models are defined in the db/prisma/schema.prisma file:
- User - User model, stores basic user information (email, name, avatar, etc.)
- Account - Account model, stores OAuth account information and credentials
- Session - Session model, stores user session information (token, expiration time, IP address, etc.)
- Verification - Verification model, stores email verification and other verification information
Authentication Configuration
ShipNowKit's authentication configuration is dynamically loaded through the configuration manager, supporting online modification of authentication settings. You can configure authentication in the Dashboard settings page:
- Enable/disable various authentication methods
- Configure OAuth provider client IDs and secrets
- Set email verification related options
Configuration is stored in the SystemConfig table, supporting both environment variables and database configuration.
Quick Start
Client-Side Usage
In client components, you can use the useSession hook to get the current user session:
import { useSession } from "@/lib/auth-client";
export function MyComponent() {
const { data: session, isPending } = useSession();
if (isPending) {
return <div>Loading...</div>;
}
if (!session) {
return <div>Please sign in</div>;
}
return <div>Welcome, {session.user.name}!</div>;
}Server-Side Usage
In server components or API routes, you can use the getSession function:
import { getSession } from "@/lib/actions/auth";
export default async function MyPage() {
const session = await getSession();
if (!session) {
redirect("/signin");
}
return <div>Welcome, {session.user.name}!</div>;
}Update Schema and Migrate Changes
Learn how to update Prisma Schema and migrate database changes. Understand how to add new models, modify existing models, and safely apply changes to your database.
User and Session Management
Learn how to access user and session information in ShipNowKit applications. Guide for using useSession hook and getSession function for authentication state management.