Community编程与开发github.com

KrostyMall/Landing-SENSORITY

为 TanStack Start 应用添加用户账户和登录功能。当应用需要身份验证、登录、用户账户、受保护路由或按用户区分数据时使用。触发词包括:auth、login、log in、sign in、sign up、account、users、authentication、protected、who is logged in、current user、per-user。

Landing-SENSORITY 是什么?

该技能为 TanStack Start 应用提供了一套完整、开箱即用的身份验证系统。它基于 Better Auth 构建,在 `/api/auth/*` 路径下运行,并通过 `genericOAuth` 插件联合到共享的 Grok 身份代理(`auth.grok.me`)。模板已预装 Google 和 X 的 OAuth 登录、电子邮件/密码登录三种方式,并明确禁止使用其他任何社交登录或认证方法(如 GitHub、Apple、魔法链接、OTP 等)。技能细节严格规定了开发流程:登录默认处于关闭状态,通过删除 `.grok/app-env.json` 中的 `VITE_AUTH_ENABLED` 开关并复制迁移文件来启用。它禁止开发者创建虚假或硬编码用户,也禁止手动修改 `src/lib/auth/` 目录下的预置文件(`email-password.ts` 除外)。同时,该技能提供了完整的用户数据安全模型,要求所有操作按用户 ID 范围查询,并使用 `authMiddleware` 保护服务器端函数。还包含预置的 UI 组件如 `UserButton`、`SignedIn`/`SignedOut` 门控、以及 `useCurrentUser()` 和 `useCurrentUserState()` 钩子,帮助开发者快速且安全地构建包含身份验证的应用。对应用户数据必须通过 `context.userId` 进行隔离,杜绝客户端伪造的用户 ID。登录弹窗由 Vite 插件自动处理,开发者无需自行创建路由或页面。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/KrostyMall/Landing-SENSORITY/tree/HEAD/.grok/skills/auth

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

身份验证 (Auth)

此应用在 /api/auth/* 下运行其自身的 Better Auth,通过 genericOAuth 插件与共享的 Grok 身份代理 (auth.grok.me) 进行联合。此模板已预配好 Google 和 X。

支持的登录方式——仅限以下三种,不支持其他任何方式:Google、X 和电子邮件/密码。 不支持其他社交/OAuth 提供商(GitHub、Apple、Discord……),不支持魔法链接、密钥、OTP、电话/SMS 或匿名登录。请勿向 GROK_PROVIDERS 添加条目。方式详情及电子邮件/密码开关(仅编辑 src/lib/auth/email-password.ts):references/sign-in-methods.md。 例外情况——门控查看者已经登录;绝不要为他们渲染登录/重新认证按钮。连接器/应用数据应用:仅限门控“继续使用 Grok”,没有 Google/X 按钮:references/grok-identity.md。

登录默认处于关闭状态——模板附带 .grok/app-env.json,内容为 {"VITE_AUTH_ENABLED": "false"},因此仅在需求明确要求时才添加账户(参见 AGENTS.md §0.5)。启用登录的操作如下方的“开启登录”。

一旦开启,登录是真实的——包括在沙箱实时预览中。 请不要搭建演示/模拟/硬编码的用户。预览:弹出窗口 + 集成好的预览客户端;部署后:每个应用的客户端 + DATABASE_URL + 零点击门控登录(references/prewired-and-env.md)。

当处于关闭状态时(VITE_AUTH_ENABLED=false),会返回一个开发用户,以便非认证应用在访客未登录的情况下仍能渲染——仅限开发和预览。部署后,该标志由平台决定(始终为 "true"),因此 requireUserId 会拒绝每一位访客——认证关闭的应用既不会使用它,也不会使用 authMiddleware。

所有内容均已预装并预配在 src/lib/auth/ 中——请勿执行 npm install 任何内容;better-auth 是唯一的认证包(绝不能使用 @neondatabase/*、@stackframe/* 或 @clerk/*)。请勿编辑或重写 src/lib/auth/ 下的任何文件——尤其是 server.ts——但 email-password.ts 中的标志除外。每个文件的用途说明:references/prewired-and-env.md。

/auth/popup 已由模板 Vite 插件处理(vite.config.ts → popup.server.ts):它永远不会渲染 React 应用。请勿创建 src/routes/auth/popup.tsx(或该路径下的任何 React 页面/客户端 OAuth)——这会使整个应用显示在弹出窗口内,这是常见的错误模式。

请勿在此沙箱中编写 .env / .env.local / .env.example:实时预览不需要任何环境配置,部署后的应用会由平台注入其变量。存在的控制选项在 references/prewired-and-env.md 中——切勿将非 VITE_ 前缀的变量暴露给客户端。

migrations/auth/0001_auth.sql 是 Better Auth 的模式定义——请勿修改。它位于全局匹配的 migrations/ 目录之外(两个应用均不会向下处理),因此不会应用于没有登录功能的应用;“开启登录”时会将其复制上来。

开启登录

执行以下所有步骤——仅添加路由就会渲染分支的禁用状态:

  1. 标志: 从 .grok/app-env.json 中删除 VITE_AUTH_ENABLED 键,然后重启开发服务器。Vite 在启动时读取环境变量,因此 HMR 不会捕获变更。npm run dev、npm run build 和 npm run preview 都通过 scripts/with-app-env.mjs 读取该文件,因此预览和构建输出会同时切换——绝不要直接启动 Vite。
  2. 模式定义: 执行 cp migrations/auth/0001_auth.sql migrations/0001_auth.sql,然后重启以便应用它。它根据 basename 在 _migrations 中跟踪,因此已包含该模式的数据库不会重复运行。
  3. 路由: 添加 src/routes/api/auth/$.ts + src/routes/login.tsx——两者均从 references/wiring.md 复制(catch-all API 路由是实现 /api/auth/* 和代理回调的关键)。
  4. 退出登录: 只有登录没有退出的功能是不完整的——从 @/lib/auth/gates 渲染 <UserButton />(它封装了 signOut();对门控会话隐藏退出按钮)。
  5. 现有数据: 将应用的服务器函数包装在 authMiddleware 中(一个认证关闭的应用之前不应该使用它——参见 neon 技能)。在启用登录之前就存在的行是开发数据:除非用户另有要求,否则应删除并重新创建它们——不要将数据交给第一个登录的人。

开启后的进一步使用

  • 登录/退出: 使用来自 @/lib/auth/client 的 signIn(providerId) 和 signOut();GROK_PROVIDERS 负责渲染按钮。弹出窗口、令牌传递和请求附加等内部机制——请保持原样。优先使用 <UserButton />(它处理了待定和失败状态);部署后如果服务器未确认,signOut() 会拒绝——请捕获异常。绝不要使用 authClient.signOut():它会使预览令牌附加到后续每个请求,导致访客保持登录状态。
  • 读取用户: useCurrentUser() 仅用于显示(null 表示加载中或已退出,因此不要仅凭它重定向);应使用 useCurrentUserState() 的 isPending 进行判断。门控组件(SignedIn、SignedOut、SignInGate、RedirectToSignIn、UserButton)位于 @/lib/auth/gates 中。CTA 硬性规则、骨架屏和 Cookie SSR 零闪烁:references/session-ui.md。
  • 按用户区分的数据(必须): 每个涉及按用户区分数据的服务器函数都必须使用预配的 authMiddleware,并将每次读和写限定为 context.userId——PostgreSQL 驱动程序具有完整的数据库访问权限,因此没有其他东西能限制查询。请保持 user_id 列为 TEXT 类型;绝不信任客户端提供的用户 ID;用户退出时,中间件会抛出 UnauthorizedError(401 状态码)。代码和禁用模式下的语义:references/per-user-data.md。
  • 安全模型: 无头代理、__Host- 前缀的 Cookie + trustedOrigins,以及基于 Fetch-Metadata 的同级隔离均已预配——绝不要为了消除某个错误而削弱它们(references/sign-in-methods.md 涵盖了模型和“无效源”错误的修复方法)。

Individual skills in this repo

This repo contains 4 individual skills — each has its own dedicated page.

KrostyMall/Landing-SENSORITY

Build browser games and interactive/canvas/3D experiences in this TanStack Start + React app. Use for any game, simulation, or WebGL/Canvas experience — 2D or 3D, single-player. Covers the game loop & timing, 3D orientation/camera conventions, collision, performance, assets, audio, save, game feel, and per-genre playbooks. For WASD / vehicle / flight **input signs and inverted A/D**, open the **`controls`** skill — do not rely on this file or racing-kart alone. Triggers on "game", "minecraft", "fps", "platformer", "racing", "tetris", "snake", "shooter", "3d", "three.js", "canvas", "voxel", "physics".

KrostyMall/Landing-SENSORITY

Player-facing input signs for browser games: WASD, vehicles, flight, FPS mouse-look, and the #1 failure mode (inverted A/D). Mandatory control self-tests and a tiny test interface so you can verify A turns left before shipping. Load for ANY game with movement, steering, flying, driving, tanks, boats, mechs, drones, planes, karts, third-person follow cams — not only racing. Triggers on "controls", "WASD", "inverted", "steer", "flight", "airplane", "kart", "vehicle", "yaw", "roll", "pitch", "mouse look", "A/D".

KrostyMall/Landing-SENSORITY

Design and build polished, non-generic UI for this TanStack Start + React + Tailwind v4 + shadcn/Radix app. Use whenever you create or restyle any interface surface — pages, landing pages, dashboards, forms, modals, nav, and game overlays (start screens, HUD, menus). Covers design tokens, layout, typography, color, spacing, motion, and the anti-"AI-slop" rules that keep output from looking generic. Triggers on "design", "UI", "make it look good", "polish", "landing page", "theme", "style", "redesign", "ugly", "clean up".

KrostyMall/Landing-SENSORITY

Deep guide for game ANIMATION assets: motion cycles, action keyframes, effect sequences, and animation sprite sheets — built around a video-first pipeline. In this app-builder sandbox, execute via the video2dsprite / generate2dsprite skills (magenta + scripts), not ad-hoc ffmpeg. Use whenever generating anything that moves: walk/run cycles, attacks, idles, FX, flags, fire, animation sheets. Complements game-asset-core.

相关技能