This repository hosts a compact Twitter-style social app built on the Next.js App Router. Visitors sign in with GitHub through NextAuth, gaining access to protected pages where they can browse profiles and toggle follow relationships. Prisma talks to a local SQLite database file, while TanStack React Query keeps client views aligned with server state.
- Next.js 15 (App Router, TypeScript, Turbopack dev server)
- React 19 with Tailwind CSS utility styling
- NextAuth + Prisma adapter with GitHub OAuth
- Prisma ORM backed by SQLite (
prisma/db.sqlite) - TanStack React Query and Axios for data fetching
src/app/layout.tsxwires global providers (session + React Query) and base styles.src/app/page.tsxserves the public landing screen and redirects authenticated users to/app.src/app/app/layout.tsxprotects the authenticated area and renders the navigation shell.src/app/app/page.tsxandsrc/app/app/profile/[userId]/page.tsxrender protected content, including profile views and follow/unfollow interactions.src/app/componentscontains reusable client helpers such as the navigation menu,QueryProvider, and the exported NextAuthSessionProvider.src/app/api/**/*exposes Next.js route handlers for auth, profile lookup, and follow toggling.src/lib/axios.tscentralises browser-side API calls;src/lib/prisma.tsexports the Prisma client singleton used by route handlers.
prisma/schema.prisma defines the schema: User, OAuth Account, Session, VerificationToken, and the Follow join model. Migrations live under prisma/migrations, and the working SQLite file is prisma/db.sqlite.
GitHub OAuth credentials load from environment variables and feed into NextAuth. Successful sign-in creates or links a User record through the Prisma adapter. Server components use getServerSession(authOption) to guard routes, and client components rely on useSession for user context.
GET /api/get-current-userreturns the signed-in user document.GET /api/get-user/[userId]returns a profile, related follow lists, and whether the viewer follows the profile.POST /api/follow-user/[userId]toggles the follow state between the requester and target user. Each route validates the session before accessing Prisma.
Create a .env file in the project root:
DATABASE_URL="file:/absolute/path/to/prisma/db.sqlite"
NEXTAUTH_SECRET="your_nextauth_secret"
GITHUB_ID="your_github_oauth_client_id"
GITHUB_SECRET="your_github_oauth_client_secret"
Update the placeholders with your actual values and restart the dev server whenever the file changes.
package.json exposes the following npm scripts:
npm run dev– start the Next.js dev server with Turbopack.npm run build– create an optimized production build.npm run start– run the production build locally.npm run lint– execute ESLint (vianext lint).
Useful supporting commands:
npm install– install dependencies.npx prisma migrate deploy– apply migrations to the SQLite database.npx prisma studio– inspect and edit database records through Prisma Studio.
- Install dependencies:
npm install - Apply migrations (optional for a clean DB):
npx prisma migrate deploy - Ensure
.envcontains validDATABASE_URL,NEXTAUTH_SECRET,GITHUB_ID, andGITHUB_SECRET - Launch the dev server:
npm run dev - Lint when needed:
npm run lint
Visit http://localhost:3000 for the landing page. Signing in with GitHub redirects you to /app, unlocking the authenticated navigation shell and profile experience.