Download the PHP package aliziodev/laravel-next-starter-kit without Composer
On this page you can find all versions of the php package aliziodev/laravel-next-starter-kit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aliziodev/laravel-next-starter-kit
More information about aliziodev/laravel-next-starter-kit
Files in aliziodev/laravel-next-starter-kit
Package laravel-next-starter-kit
Short Description A decoupled Laravel (API) + Next.js starter kit with Fortify + Sanctum authentication, powered by next-sanctum.
License MIT
Informations about the package laravel-next-starter-kit
Laravel + Next.js Starter Kit
A decoupled starter kit: a headless Laravel API and a separate Next.js (App Router) frontend, wired together with Laravel Fortify + Sanctum and the next-sanctum client.
It mirrors the UI and feature set of the official laravel/react-starter-kit, but instead of Inertia it ships an independent SPA that talks to Laravel over a same-origin proxy (no CORS).
Architecture
The browser only ever talks to the Next.js origin. The route handler forwards requests to Laravel carrying the session cookie and Origin/Referer, so Sanctum treats the SPA as first-party (stateful) — no CORS. Server Components authenticate directly via getUser() / serverFetch() from next-sanctum/server.
Login (cookie/SPA) flow
Auth boundaries
Protected pages live in an (app) route group whose layout calls getUser() once and redirects guests to /login — the decoupled equivalent of Route::middleware('auth')->group(...); auth pages live in (auth). Only those groups mount the Sanctum provider, so public pages (e.g. the welcome page) stay provider-free. The authoritative security boundary is the API itself (auth:sanctum); proxy.ts is only an optimistic edge fast-path.
Features
- Authentication — login, registration, password reset, password confirmation
- Two-factor authentication (TOTP) — QR setup, confirmation, recovery codes, login challenge
- Passkeys (WebAuthn) — passwordless sign-in + management, via
laravel/passkeysand@laravel/passkeys - Email verification — opt-in (off by default, like the official kit — see below)
- Browser sessions — list devices, log out one or all other sessions (password-confirmed), over the framework
sessionstable - Settings — profile, password, appearance (light/dark/system), account deletion
- App shell — sidebar/header layouts, breadcrumbs, user menu, dashboard
- Dark mode (
next-themes), toasts (sonner), shadcn/ui (Nova preset), Tailwind v4, React 19
Requirements
- PHP 8.4+ and Composer
- Node 20+ and pnpm (
corepack enable pnpm)
Quick start
Open http://localhost:3000 and register an account. The API runs on http://localhost:8000.
Laravel installer prompts: when
laravel newasks "runnpm install --ignore-scriptsandnpm run build?", answer no — this kit's frontend lives inweb/(pnpm) and is installed in step 2. Atests.ymlwarning is harmless (this kit's CI workflow ise2e.yml). Choose Pest when asked for a testing framework (this kit's backend tests use Pest); Laravel Boost is optional (dev-only AI tooling).The root
package.jsononly delegatesdev/buildtoweb/, socomposer run devkeeps working even though the installer rewrites itsdevscript to callnpm run dev.Already have a clone? Run
composer run setuponce to copy env files, generate the app key, migrate, and install the web dependencies.
Project structure
Environment
Backend (.env):
| Variable | Purpose |
|---|---|
FRONTEND_URL |
Where email links (verify / reset) point back to (the SPA). |
SANCTUM_STATEFUL_DOMAINS |
First-party origins for cookie auth — must list :3000 + :8000. |
SESSION_DRIVER=database |
Required for the cookie/SPA flow. |
SESSION_COOKIE |
Pinned to laravel_session for the proxy's cookie check. |
Frontend (web/.env.local):
| Variable | Purpose |
|---|---|
NEXT_PUBLIC_SANCTUM_BASE_URL |
Client base URL → the same-origin proxy (/api/sanctum). |
SANCTUM_BASE_URL |
Server-only upstream → the real Laravel origin. |
Deployment (Docker)
Even though the stack is two runtimes (Node + PHP), Docker Compose turns it into one command — you never run Node or PHP yourself. Thanks to the same-origin proxy, only the Next.js container is public; Laravel, MySQL, and the workers stay on the internal network.
Prerequisite: Docker + Docker Compose.
Open http://localhost:3000. That's it — on first boot the stack generates APP_KEY, runs migrations, and builds the prod caches (config/route/event) automatically.
| Service | Role | Public? |
|---|---|---|
frontend |
Next.js (standalone build) | ✅ yes |
api |
nginx → php-fpm (Laravel) | no |
php |
Laravel (php-fpm) — migrates + caches on boot | no |
queue |
queue:work (verification / reset emails) |
no |
scheduler |
schedule:work |
no |
db |
MySQL 8 | no |
Before a real (public) deploy, edit .env.docker:
FRONTEND_URL→ your public frontend URL (used in email links).SANCTUM_STATEFUL_DOMAINS→ your public frontend domain, plus the internalapihost (e.g.app.example.com,api).SESSION_SECURE_COOKIE=trueonce you serve over HTTPS.DB_PASSWORD/DB_ROOT_PASSWORD→ real secrets.MAIL_MAILER→ a real SMTP provider (defaults tolog).
Put a TLS reverse proxy (Caddy / Traefik / your platform) in front of frontend. The same docker-compose.yml also deploys as-is on PaaS that consume Compose files (e.g. Coolify, Railway), so you can skip managing a server entirely.
Redis is optional. Session / cache / queue default to the database driver (zero extra services). Switch
SESSION_DRIVER/CACHE_STORE/QUEUE_CONNECTIONtoredisand add aredisservice if you want it.
Security
- No CORS: the browser only calls the Next.js origin; the route proxy forwards to Laravel server-side. The API is never exposed cross-origin to the browser.
- Stateful cookie auth: Sanctum's
statefulApi()authenticates the SPA via anHttpOnlysession cookie. Only origins listed inSANCTUM_STATEFUL_DOMAINSare treated as first-party. - CSRF: every mutating request carries the
XSRF-TOKENcookie as anX-XSRF-TOKENheader;next-sanctumattaches it and transparently refreshes + retries once on a 419. - Password confirmation: sensitive actions (managing passkeys, deleting the account, enabling/disabling 2FA) sit behind Fortify's password-confirmation window (
password.confirm); logging out other browser sessions re-validates the current password in the request itself. - Two-factor authentication: TOTP with a required confirmation step, single-use recovery codes, and password-confirmed enable/disable.
- Passkeys (WebAuthn): Fortify (>= 1.37) owns the passkey routes, so the relying-party ID and
allowed_originsare configured inconfig/fortify.php(passkeyskey) —allowed_originsmust include the SPA origin (FRONTEND_URL, e.g.:3000) since the browser runs the ceremony there. Registration requires resident keys + user verification, management is password-confirmed, and the endpoints are rate limited (6,1). Uselocalhost(not127.0.0.1) in development so the origin matches the relying-party ID. - Rate limiting: Fortify throttles login attempts (5/min per email + IP); passkey endpoints use
throttle:6,1. - API tokens: Sanctum personal-access tokens are available for mobile / third-party clients via
Authorization: Bearer <token>(the SPA itself uses cookies). - Going to production: serve both apps over HTTPS; set
APP_URL,FRONTEND_URL, andSANCTUM_STATEFUL_DOMAINSto your real domains; setSESSION_DOMAIN(e.g..example.com) for cross-subdomain cookies; setAPP_DEBUG=false; and configure a real mailer.
Testing
End-to-end (Playwright, Chromium) — drives the full stack and covers login, invalid credentials, registration, logout, the passkey ceremony (register + passwordless sign-in, via a CDP virtual authenticator), 2FA (enable + login challenge, via a computed TOTP), and browser sessions (a second device's session listed + logged out). No real device is needed.
Locally the suite reuses already-running dev servers; in CI it boots them itself. GitHub Actions runs it on every push / PR (.github/workflows/e2e.yml).
Backend (Pest):
Lint & format:
All three suites run in GitHub Actions on every push / PR — tests.yml (Pest, PHP 8.4/8.5), lint.yml (Pint + ESLint + Prettier), and e2e.yml (Playwright).
Email verification
Email verification is off by default, matching the official Laravel starter kit. To enable it:
- In
web/lib/email-verification.ts, setMUST_VERIFY_EMAIL = true. - In
app/Models/User.php, uncomment theMustVerifyEmailimport and add it to theimplementslist so Fortify sends verification emails.
The verify-email pages and the resend flow ship ready to use; the flag simply gates the UI enforcement.
License
MIT.
All versions of laravel-next-starter-kit with dependencies
laravel/fortify Version ^1.37
laravel/framework Version ^13.8
laravel/passkeys Version ^0.2.1
laravel/sanctum Version ^4.3
laravel/tinker Version ^3.0