Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lucia and setup session authentication from scratch #83

Draft
wants to merge 38 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9e4d7ec
adapters
iamtouha Nov 23, 2024
9b30a1b
wip
iamtouha Nov 23, 2024
d1a4af4
wip
iamtouha Nov 24, 2024
1306e0a
replace lucia on actions
iamtouha Nov 24, 2024
02dcfd0
Refactor authentication imports and session handling across multiple …
iamtouha Nov 24, 2024
f0a21ad
remove lucia dependency
iamtouha Nov 24, 2024
d610482
wip
iamtouha Dec 23, 2024
8b71a5f
dependency update
iamtouha Jan 6, 2025
03f6de5
Refactor login component and implement new TextInput component for be…
iamtouha Jan 7, 2025
79f23a0
update dependencies and refactor login/signup actions
iamtouha Jan 7, 2025
740b46d
Refactor
iamtouha Jan 18, 2025
6a528d5
Merge branch 'main' into feat/remove-lucia
iamtouha Jan 18, 2025
ce9fa3d
Refactor authentication actions
iamtouha Jan 18, 2025
bf7458b
fix lint issues
iamtouha Jan 18, 2025
b660350
migrate broken components
iamtouha Jan 18, 2025
9dddee5
server component related fixes
iamtouha Jan 18, 2025
f2eeaf8
Merge branch 'main' into feat/remove-lucia
iamtouha Jan 20, 2025
1198d02
cleanup
iamtouha Jan 20, 2025
2824c96
Update devcontainer configuration for Next.js development environment
iamtouha Jan 20, 2025
ed60ff5
Refactor: Update icon imports and improve accessibility in user dropd…
iamtouha Jan 20, 2025
47ea84e
next version update
iamtouha Jan 20, 2025
e75c754
Refactor: Improve user dropdown rendering and update dashboard layout…
iamtouha Jan 20, 2025
49f91bb
update Discord authentication logic to use new utility functions and …
iamtouha Jan 20, 2025
9f07467
update ci
iamtouha Jan 20, 2025
9ef1129
update authentication actions
iamtouha Jan 20, 2025
981455c
update success state checks in authentication components for clearer …
iamtouha Jan 21, 2025
6195ee8
simplify post creation and update logic; streamline column selection …
iamtouha Jan 21, 2025
6adcfe9
update footer links to reflect new repository and organization; adjus…
iamtouha Jan 21, 2025
dfb656e
schema update wip
iamtouha Jan 21, 2025
b70f8d0
update
iamtouha Jan 21, 2025
cadb078
simplify post status definition
iamtouha Jan 21, 2025
8c88df0
update
iamtouha Jan 21, 2025
88fa666
limit user posts to a maximum of 5; update schema for consistency and…
iamtouha Jan 21, 2025
88b203a
fix
iamtouha Jan 21, 2025
cbff8ff
docs wip
iamtouha Jan 21, 2025
9f15aab
wip
iamtouha Jan 22, 2025
d393d03
wip
iamtouha Jan 22, 2025
d8f4183
refactor(auth): simplify adapter interface and improve session handling
iamtouha Jan 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .devcontainer/compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
services:
workspace:
build:
build:
dockerfile: Dockerfile
volumes:
- ../:/workspace:cached
command: /bin/sh -c "while sleep 1000; do :; done"
command: /bin/sh -c "while sleep 1000; do :; done"
depends_on:
- database

database:
image: postgres:17.2-alpine
environment:
POSTGRES_DB: acme
POSTGRES_USER: postgres
POSTGRES_PASSWORD: root

ports:
- 5432:5432
20 changes: 17 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
{
"name": "Next.js Auth Template",
"name": "Next.js Dev",
"dockerComposeFile": ["compose.dev.yml"],
"service": "workspace",
"workspaceFolder": "/workspace",
"postCreateCommand": "pnpm config set store-dir $HOME/.pnpm-store",
"postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh",
"postStartCommand": "pnpm install",
"forwardPorts": [3000],
"forwardPorts": [3000, 9323, 4983],
"portsAttributes": {
"3000": {
"label": "Next.js Server",
"onAutoForward": "silent"
},
"9323": {
"label": "Playwright Reports",
"onAutoForward": "silent"
},
"4983": {
"label": "Drizzle-kit Studio",
"onAutoForward": "silent"
}
},
"features": {
"ghcr.io/devcontainers-extra/features/pnpm": "latest"
},
Expand Down
4 changes: 4 additions & 0 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

pnpm config set store-dir $HOME/.pnpm-store
pnpm exec playwright install chromium --with-deps
5 changes: 4 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ const config = {
fixStyle: "inline-type-imports",
},
],
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
"@typescript-eslint/no-unused-vars": [
"warn",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],
"@typescript-eslint/require-await": "off",
"@typescript-eslint/no-misused-promises": [
"error",
Expand Down
41 changes: 25 additions & 16 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

env:
DATABASE_URL: postgres://postgres:root@localhost:5432/acme
DISCORD_CLIENT_ID: ${{secrets.DISCORD_CLIENT_ID}}
DISCORD_CLIENT_SECRET: ${{secrets.DISCORD_CLIENT_SECRET}}
MOCK_SEND_EMAIL: "true"
SMTP_HOST: host
SMTP_PORT: 587
SMTP_USER: user
SMTP_PASSWORD: password
NEXT_PUBLIC_APP_URL: http://localhost:3000
STRIPE_API_KEY: stripe_api_key
STRIPE_WEBHOOK_SECRET: stripe_webhook_secret
STRIPE_PRO_MONTHLY_PLAN_ID: stripe_pro_monthly_plan_id

permissions:
contents: read

Expand All @@ -30,27 +44,22 @@ jobs:

- name: Type Check and Lint
run: pnpm run typecheck && pnpm run lint
env:
SKIP_ENV_VALIDATION: true

e2e-test:
needs: typecheck-and-lint
timeout-minutes: 60
runs-on: ubuntu-latest

env:
DATABASE_URL: ${{secrets.DATABASE_URL}}
DISCORD_CLIENT_ID: ${{secrets.DISCORD_CLIENT_ID}}
DISCORD_CLIENT_SECRET: ${{secrets.DISCORD_CLIENT_SECRET}}
MOCK_SEND_EMAIL: "true"
SMTP_HOST: host
SMTP_PORT: 587
SMTP_USER: user
SMTP_PASSWORD: password
NEXT_PUBLIC_APP_URL: http://localhost:3000
STRIPE_API_KEY: stripe_api_key
STRIPE_WEBHOOK_SECRET: stripe_webhook_secret
STRIPE_PRO_MONTHLY_PLAN_ID: stripe_pro_monthly_plan_id
services:
postgres:
image: postgres:17.2-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: root
POSTGRES_DB: acme
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v2
Expand All @@ -62,7 +71,7 @@ jobs:
node-version: 20.x
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
run: pnpm install --frozen-lockfile && pnpm db:push
- name: Build the app
run: pnpm build
- name: Install Playwright Browsers
Expand Down
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
# Next.js Auth Starter Template
# Next.js Session-based Auth Starter Template

## Motivation

Implementing authentication in Next.js, especially Email+Password authentication, can be challenging. NextAuth intentionally limits email password functionality to discourage the use of passwords due to security risks and added complexity. However, in certain projects, clients may require user password authentication. Lucia offers a flexible alternative to NextAuth.js, providing more customization options without compromising on security. This template serves as a starting point for building a Next.js app with Lucia authentication.

## Lucia vs. NextAuth.js

Lucia is less opinionated than NextAuth, offering greater flexibility for customization. While Lucia involves more setup, it provides a higher degree of flexibility, making it a suitable choice for projects requiring unique authentication configurations.
Implementing authentication in Next.js, especially Email+Password authentication, can be challenging. NextAuth intentionally limits email password functionality to discourage the use of passwords due to security risks and added complexity. However, in certain projects, clients may require user password authentication. Lucia offers a flexible alternative to NextAuth.js, providing more customization options without compromising on security. This template serves as a starting point for building a Next.js app with secure session based authentication.

## Key Features

- **Authentication:** 💼 Support for Credential and OAuth authentication.
- **Authorization:** 🔒 Easily manage public and protected routes within the `app directory`.
- **Email Verification:** 📧 Verify user identities through email.
- **Password Reset:** 🔑 Streamline password resets by sending email password reset links.
- **Lucia + tRPC:** 🔄 Similar to NextAuth with tRPC, granting access to sessions and user information through tRPC procedures.
- **Auth + tRPC:** 🔄 Similar to NextAuth with tRPC, granting access to sessions and user information through tRPC procedures.
- **E2E tests:** 🧪 Catch every issue before your users do with comprehensive E2E testing.
- **Stripe Payment:** 💳 Setup user subscriptions seamlessly with stripe.
- **Email template with react-email:** ✉️ Craft your email templates using React.
Expand All @@ -24,7 +20,6 @@ Lucia is less opinionated than NextAuth, offering greater flexibility for custom
## Tech Stack

- [Next.js](https://nextjs.org)
- [Lucia](https://lucia-auth.com/)
- [tRPC](https://trpc.io)
- [Drizzle ORM](https://orm.drizzle.team/)
- [PostgreSQL](https://www.postgresql.org/)
Expand Down
4 changes: 2 additions & 2 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { defineConfig } from "drizzle-kit";
import { DATABASE_PREFIX } from "@/lib/constants";
import { defineConfig } from "drizzle-kit";

export default defineConfig({
schema: "./src/server/db/schema.ts",
schema: "./src/server/db/schema",
out: "./drizzle",
dialect: "postgresql",
dbCredentials: {
Expand Down
38 changes: 20 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,64 +18,66 @@
},
"dependencies": {
"@hookform/resolvers": "^3.9.0",
"@lucia-auth/adapter-drizzle": "1.0.7",
"@radix-ui/react-alert-dialog": "^1.1.1",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-dropdown-menu": "^2.1.1",
"@radix-ui/react-icons": "^1.3.0",
"@oslojs/crypto": "^1.0.1",
"@oslojs/encoding": "^1.1.0",
"@radix-ui/react-alert-dialog": "^1.1.4",
"@radix-ui/react-dialog": "^1.1.4",
"@radix-ui/react-dropdown-menu": "^2.1.4",
"@radix-ui/react-icons": "^1.3.2",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tabs": "^1.1.0",
"@react-email/components": "^0.0.12",
"@react-email/render": "^0.0.10",
"@react-email/components": "^0.0.31",
"@react-email/render": "^1.0.3",
"@t3-oss/env-nextjs": "^0.7.3",
"@tanstack/react-query": "^4.36.1",
"@trpc/client": "^10.45.2",
"@trpc/next": "^10.45.2",
"@trpc/react-query": "^10.45.2",
"@trpc/server": "^10.45.2",
"arctic": "^1.9.2",
"bcryptjs": "^2.4.3",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"lucia": "3.2.0",
"next": "^14.2.5",
"drizzle-orm": "^0.38.3",
"nanoid": "^5.0.9",
"next": "^15.1.5",
"next-themes": "^0.2.1",
"nodemailer": "^6.9.14",
"oslo": "^1.2.1",
"postgres": "^3.4.4",
"react": "18.2.0",
"react-dom": "18.2.0",
"react": "19.0.0",
"react-dom": "19.0.0",
"react-hook-form": "^7.52.1",
"react-markdown": "^9.0.1",
"react-syntax-highlighter": "^15.5.0",
"rehype-raw": "^7.0.0",
"remark-gfm": "^4.0.0",
"server-only": "^0.0.1",
"sonner": "^1.5.0",
"sonner": "^1.7.1",
"stripe": "^14.25.0",
"superjson": "^2.2.1",
"tailwind-merge": "^2.4.0",
"tailwindcss-animate": "^1.0.7",
"vaul": "^0.8.9",
"vaul": "^1.1.2",
"zod": "^3.23.8"
},
"devDependencies": {
"@next/eslint-plugin-next": "^14.2.5",
"@playwright/test": "^1.45.3",
"@tailwindcss/typography": "^0.5.13",
"@types/bcryptjs": "^2.4.6",
"@types/eslint": "^8.56.11",
"@types/node": "^18.19.42",
"@types/nodemailer": "^6.4.15",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react": "^19.0.3",
"@types/react-dom": "^19.0.2",
"@types/react-syntax-highlighter": "^15.5.13",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"autoprefixer": "^10.4.19",
"dotenv": "^16.4.5",
"dotenv-cli": "^7.4.2",
"drizzle-kit": "^0.23.0",
"drizzle-orm": "^0.32.1",
"drizzle-kit": "^0.30.1",
"eslint": "^8.57.0",
"pg": "^8.12.0",
"postcss": "^8.4.40",
Expand Down
Loading
Loading