| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A robust, type-safe authentication package built with NextAuth.js (Auth.js), Effect, and Prisma ORM. This package provides a complete authentication solution that can be easily integrated into other Next.js projects.
This monorepo contains the following packages:
# Clone the repository
git clone <your-repo-url>
cd next-auth
# Install dependencies
pnpm install
# Set up environment variables
cp .env.example .env.local# Database
DATABASE_URL="postgresql://user:password@localhost:5432/dbname"
# NextAuth
NEXTAUTH_SECRET="your-secret-key"
NEXTAUTH_URL="http://localhost:3000"
# Email (Resend)
RESEND_API_KEY="your-resend-api-key"# Generate Prisma client
pnpm --filter @repo/db db:generate
# Run migrations
pnpm --filter @repo/db db:migrate
# Or push schema changes
pnpm --filter @repo/db db:push# Start development mode for all packages
pnpm dev
# Build all packages
pnpm build
# Lint all packages
pnpm lint// In your Next.js app
import { authOptions } from '@repo/auth/options';
import NextAuth from 'next-auth';
export const { handlers, auth } = NextAuth(authOptions);
// API routes
export const GET = handlers.GET;
export const POST = handlers.POST;import { registerUser } from '@repo/auth/signup';
import { Effect } from 'effect';
const handleSignup = async (email: string, password: string) => {
const result = await Effect.runPromise(
registerUser({ email, password })
);
if (Effect.isSuccess(result)) {
// User created successfully
console.log('User created:', result.value);
} else {
// Handle error
console.error('Error:', result.error);
}
};import { loginEffect } from '@repo/auth/login';
import { useRouter } from 'next/navigation';
const handleLogin = async (email: string, password: string) => {
const router = useRouter();
const result = await Effect.runPromise(
loginEffect(email, password, router)
);
if (Effect.isSuccess(result)) {
// Login successful, user redirected to dashboard
} else {
// Handle login error
console.error('Login failed:', result.error);
}
};import { forgotPasswordRoute } from '@repo/auth/forgot-password-route';
import { resetPasswordRoute } from '@repo/auth/reset-password-route';
// Use in your API routes
export const POST = forgotPasswordRoute;
export const PUT = resetPasswordRoute;The package uses Effect for functional error handling and side effects:
import { Effect } from 'effect';
// All database operations are wrapped in Effect
const userResult = yield* findUserByEmail(email);
// Error handling with Effect
const result = yield* Effect.tryPromise({
try: () => bcrypt.compare(password, user.password!),
catch: (err) => new Error(`Password comparison failed: ${err}`)
});Database operations are abstracted through a service layer:
import { PrismaServiceLive, findUserByEmail } from '@repo/db';
const userEffect = Effect.gen(function* () {
const user = yield* findUserByEmail(email);
// ... rest of the logic
}).pipe(Effect.provide(PrismaServiceLive));packages/ ├── auth/ # Authentication package │ ├── src/ │ │ ├── options.ts # NextAuth configuration │ │ ├── login.ts # Login logic with Effect │ │ ├── signup.ts # User registration │ │ ├── next.ts # Next.js integration │ │ └── reset-password/ # Password reset functionality │ └── package.json ├── db/ # Database package │ ├── src/ │ │ ├── prisma-service.ts # Effect-based Prisma service │ │ ├── query.ts # Database queries │ │ └── index.ts # Exports │ ├── prisma/ # Prisma schema and migrations │ └── package.json └── ui/ # Shared UI components
This project is licensed under the MIT License.
| Back | FazBrowse Home | New Git URL |