nextauth-local-e2e-session
Skill0 starsChanged 5 months agoMITView on GitHub
next-auth(v5/JWT)+Google OAuthのみのNext.jsアプリを、本番DBに触れずローカルdevでログイン済みE2E検証したいとき。セッションCookieを自作mintし、TURSO等のDB env をfile DBに差し替えて Playwright で通す手順。
- Reads credentials
- Installs packages
In this repository99 other files it gives its agents.
- agents-tools-quoted-jsonSkill
- asc-api-app-store-submitSkill
- asd-ste100Skill
- automation-bool-selector-pitfallsSkill
- automation-stale-cooldown-flagSkill
- autonomous-build-verifySkill
- book-to-skillSkill
- ccusage-cli-cost-trackingSkill
- chrome-ext-mv3-programmatic-injectSkill
- chrome-ext-store-assetsSkill
- claude-headless-p-invocationSkill
- claude-plugin-context-auditSkill
- claude-session-log-to-kbSkill
- cloudflare-workers-do-deploySkill
- codebase-to-courseSkill
- codesign-keychain-prompt-fixSkill
- codex-cli-setupSkill
- codex-delegation-handoffSkill
- content-factory-grounding-dedupSkill
- conversation-log-append-patternSkill
- cron-to-launchd-macosSkill
- cross-automation-shared-resource-killSkill
- design-token-migration-rnSkill
- discord-bot-image-to-claudeSkill
- discord-gateway-resume-dedupSkill
- excel-filtered-url-http-auditSkill
- execution-budget-vs-capsSkill
- expo-free-local-ios-testflightSkill
- ga4-connect-projectsSkill
- gcal-oauth-desktop-setupSkill
- git-commit-helperSkill
- git-prepush-secret-remote-checkSkill
- gsc-cli-automationSkill
- hatena-blogsync-autopostSkill
- hook-latency-wrapSkill
- hook-log-append-patternSkill
- html-to-pdf-slide-deckSkill
- humanizerSkill
- human-review-gate-shellSkill
- implementation-model-routingSkill
- insights-to-claude-mdSkill
- ios-permission-key-security-matrixSkill
- ios-sim-store-screenshotsSkill
- launchd-exit78-exconfig-debugSkill
- llm-content-pipeline-quality-gateSkill
- local-ai-video-pipelineSkill
- local-flux-mflux-image-genSkill
- local-llm-slow-diagnosisSkill
- local-music-generationSkill
- lottie-skottie-authoring-pitfallsSkill
- machine-wide-api-ratelimit-latchSkill
- macos-hook-path-timeoutSkill
- md-to-docx-reportSkill
- memory-md-inject-bloat-auditSkill
- message-display-secrets-maskSkill
- metric-source-attributionSkill
- migrate-icloud-desktop-assetsSkill
- nextjs-rsc-payload-slimSkill
- nothing-designSkill
- openclaw-ollama-setupSkill
- The first 60 shown.
The file
Files
Procedure
- DB隔離: Next.js はランタイム環境変数が
.env.localより優先される。起動時に上書きして本番DBを遮断する:
注意:TURSO_DATABASE_URL="file:/tmp/<app>-e2e.db" TURSO_AUTH_TOKEN="" \ AUTH_SECRET="<使い捨てdev文字列>" AUTH_TRUST_HOST=true \ npx next dev -p 3105 > /tmp/dev.log 2>&1 # run_in_backgroundTURSO_AUTH_TOKEN=""は空文字(falsy判定でfile DBに落とすコードが多い)。URL側を空文字にするとurl ?? fallbackを素通りして壊れる。 - セッションCookie mint: プロジェクト内に一時 .mjs を置き(bare import解決のため)、同じ AUTH_SECRET で:
Cookie名はimport { encode } from "next-auth/jwt"; const token = await encode({ token: { email: "...", name: "E2E", sub: "e2e" }, secret: process.env.AUTH_SECRET, salt: "authjs.session-token", // v5: salt = cookie名 (httpsなら __Secure- 接頭辞) maxAge: 3600, });authjs.session-token(http/localhost)。signIn callbackはセッション読取時には走らないので、Googleプロバイダ無効でも auth() は通る。 - Playwright:
context.addCookies([{ name: "authjs.session-token", value, domain: "localhost", path: "/", httpOnly: true, sameSite: "Lax" }])→ 認証必須ページ・API が全部動く。 - 検証後: 一時mintスクリプト削除、
pkill -f "next dev -p <port>"、/tmpのDB破棄。
Pitfalls
- Next dev overlayの
[role=dialog]: dev modeはhiddenなエラーoverlay dialogをDOMに常駐させる。モーダルのdetach待ちは[aria-label*='...']などアプリ固有セレクタで行う。[role=dialog]は永久にdetachしない。 page.once("dialog", ...)の残骸: 「念のためaccept」を仕掛けて発火しないと、後続テストのconfirmを横取りする。confirm検証前にpage.removeAllListeners("dialog")。- playwright未インストールのプロジェクトでは
/tmpにnpm i playwrightした使い捨てprojectから実行(対象repoのpackage.jsonを汚さない)。ブラウザバイナリは~/Library/Caches/ms-playwrightに共有キャッシュ済みのことが多い。 - 検証アサートの月表示等は実レンダリング文字列(例: "2026年 6月" のスペース)に合わせる。
Verification
curl -H "Cookie: authjs.session-token=$TOKEN" http://localhost:<port>/api/<protected>が200で実データを返す/tmp/<app>-e2e.dbが生成・成長している(=本番DB非接続の証拠)- 書き込み系フロー(保存→一覧反映)をPlaywrightで通し、スクショを /tmp に保存
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

