Communitygithub.com

用户认证与登录

为 TanStack Start 应用添加用户账户和登录功能。在应用需要身份验证、登录、用户账户、受保护路由或用户专属数据时使用。触发关键词包括:“auth”、“login”、“sign in”、“sign up”、“account”、“users”、“authentication”、“protected”、“current user”、“per-user”等。

用户认证与登录 是什么?

该技能为基于 TanStack Start 的应用提供完整的用户认证系统,内置了 [Better Auth](https://better-auth.com) 服务,并通过 `genericOAuth` 插件连接到共享的 Grok 认证代理(`auth.grok.me`)。它支持三种登录方式:Google、X 以及邮箱/密码,不支持其他 OAuth 提供商、魔法链接、通行密钥、OTP 或匿名登录。认证功能默认关闭,需要通过删除 `.grok/app-env.json` 中的 `VITE_AUTH_ENABLED` 标志、复制数据库迁移文件、添加路由和退出按钮等步骤手动启用。启用后,所有涉及用户数据的服务端函数都必须使用预置的 `authMiddleware` 中间件来获取用户身份(`context.userId`),并确保所有读写操作都基于该用户 ID 进行作用域隔离,以保证数据安全。该技能适用于需要用户账户、受保护路由或个性化数据的所有场景。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/evalix098/tiktoklive/tree/HEAD/.grok/skills/auth

在你喜欢的 AI 中提问

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

文档

用户认证与登录 是做什么的?

此应用在 /api/auth/* 路径下运行其自有的 Better Auth 服务,并通过 genericOAuth 插件连接到共享的 Grok 认证代理 (auth.grok.me)。该模板已预配好 Google 和 X 的登录渠道。

支持的登录方式——仅限以下三种,其他方式均不支持:Google、X 以及邮箱/密码。 不要添加其他社交/OAuth 提供商(如 GitHub、Apple、Discord 等),也不支持魔法链接、通行密钥、一次性密码、手机/SMS 或匿名登录。请勿向 GROK_PROVIDERS 添加任何条目。关于各登录方式的详细说明以及邮箱/密码开关(仅编辑 src/lib/auth/email-password.ts),请参见 references/sign-in-methods.md。 例外情况——看门人(gate viewer)用户已经登录,绝不要为他们渲染登录/重新认证按钮。对于连接器/应用数据类应用,仅显示“继续使用 Grok”按钮,不显示 Google/X 按钮,详见 references/grok-identity.md。

登录功能默认关闭——模板附带的 .grok/app-env.json 中设置为 {"VITE_AUTH_ENABLED": "false"},因此仅在需要用户账户时(参见 AGENTS.md §0.5)才开启此功能。开启过程请参考下方“开启登录功能”。

一旦开启,登录功能是真实的——包括在沙箱实时预览中也是如此。 请不要创建 demo/模拟/硬编码的用户。预览模式下:弹出窗口 + 内置预览客户端;部署后:每个应用有自己的客户端 + 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,然后重启以使模式生效。该文件通过基本名称在 _migrations 表中跟踪,因此已应用过的数据库不会重复执行。
  3. 路由: 添加 src/routes/api/auth/$.ts 和 src/routes/login.tsx——从 references/wiring.md 复制这两个文件(通配 API 路由是使 /api/auth/* 和代理回调生效的关键)。
  4. 退出登录: 有登录没有退出是不完整的——渲染来自 @/lib/auth/gates 的 <UserButton /> 组件(它连接到 signOut() 函数;对看门人会话隐藏退出按钮)。
  5. 现有数据: 将应用的服务器函数包装在 authMiddleware 中(关闭认证的应用之前不应使用该中间件——参见 neon 技能)。在启用登录之前已有的行是开发数据:除非用户另有要求,否则应删除并重新创建它们——不要将其交给第一个登录的用户。

开启后的进一步构建

  • 登录/退出: 使用 @/lib/auth/client 中的 signIn(providerId) 和 signOut() 函数;GROK_PROVIDERS 负责渲染按钮。弹出窗口、Bearer Token 传递以及请求附加等内部机制请勿修改。优先使用 <UserButton />(它会处理待处理和失败状态);signOut() 在部署后如果服务器未确认会拒绝操作——请捕获该异常。不要使用 authClient.signOut():它会使预览的 Bearer Token 附加到后续所有请求,导致访客始终处于登录状态。
  • 读取用户信息: useCurrentUser() 仅用于显示(null 表示“加载中”或“已注销”,因此不要单独依赖它进行重定向);应使用 useCurrentUserState() 的 isPending 属性进行守卫。守卫组件(SignedIn、SignedOut、SignInGate、RedirectToSignIn、UserButton)位于 @/lib/auth/gates。关于 CTA 硬规则、骨架屏以及基于 Cookie 的 SSR 无闪烁方案,请参见 references/session-ui.md。
  • 用户专属数据(必需): 每个操作用户数据的服务端函数都必须使用预置的 authMiddleware,并且所有读和写操作都要作用域限制在 context.userId 中——Postgres 驱动程序拥有完整的数据库访问权限,因此没有其他限制能约束查询。请将 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 17 individual skills — each has its own dedicated page.

evalix098/tiktoklive

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".

evalix098/tiktoklive

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".

evalix098/tiktoklive

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".

evalix098/tiktoklive

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.

evalix098/tiktoklive

Core discipline for ANY game-asset generation with Imagine tools: the engine-ready defaults users don't state, spec checklists, style anchoring, read-back verification, honest defect flagging. Use whenever generating any game art (sprites, sheets, animations, tiles, UI, FX) — then ALSO load the matching specialist skill: game-animation-frames for anything that moves, game-tilesets for tiles/terrain, game-character-consistency for recurring characters, game-ui-icons for UI and icons.

evalix098/tiktoklive

Deep guide for CHARACTER IDENTITY across images: turnarounds (front/side/ back), state and damage variants, palette swaps, equipment changes, and same-character-in-context sets. Use whenever generating character turnarounds, character sheets, variants of an existing sprite, or any same-subject multi-image set. Complements game-asset-core.

evalix098/tiktoklive

Deep guide for game TILE assets: seamless tileable textures, terrain transition tilesets, autotiles, and ground/platform tiles. Use whenever generating tileable textures, tilesets, terrain transitions, or seamless patterns. Complements game-asset-core.

evalix098/tiktoklive

Deep guide for game UI assets: buttons with interaction states, panels, bars, wordmark logos, and icon sets. Use whenever generating game UI elements, HUD assets, inventory icons, icon sets, buttons, or title logos. Complements game-asset-core.

evalix098/tiktoklive

Generate production-oriented 2D game maps with `imagine_text_to_image`: RPG/top-down maps, side-scroller parallax stages, tilemaps, layered raster maps, prop packs, collision zones, and walkable areas. Use when building browser games that need real map art (not pure code-drawn tiles), layered props, or map collision metadata. Triggers on "map", "level", "stage", "tilemap", "overworld", "dungeon", "side scroller background", "prop pack", "2D map".

evalix098/tiktoklive

Generate and postprocess 2D game sprites and animation sheets: pixel-art characters, NPCs, creatures, spells, projectiles, impacts, props, summons, and transparent PNG/GIF exports. Use when building browser games that need real sprite sheets (not code-drawn placeholders), matching a map art style, or producing magenta-background sheets for chroma-key cleanup. Triggers on "sprite", "sprite sheet", "animation sheet", "pixel art character", "walk cycle", "attack animation", "projectile sprite", "2D game asset".

evalix098/tiktoklive

How to use the Imagine tools in Grok Build: imagine_text_to_image, imagine_image_to_image, imagine_reference_to_image, imagine_text_to_video, imagine_image_to_video, imagine_reference_to_video, and render_file for chat previews. When to build a visual with code instead of generating it, prompt-craft, reference-first handling of real people, factual grounding, and asset-consistency. Load this whenever generating or editing an image or video is on the table. Tool-usage-driven, not triggered by a user merely mentioning images.

evalix098/tiktoklive

Peer-to-peer realtime multiplayer over WebRTC data channels: every user of the deployed app connects directly to every other user (full mesh), the server only brokers the handshake at /api/rtc. Lowest possible latency, zero per-message server cost. Use for 2-8 player co-op/casual realtime: shared cursors, drawing, party games, casual action. Triggers: p2p, peer to peer, webrtc, low latency multiplayer, direct connection.

evalix098/tiktoklive

Use Neon Postgres (the database) in this TanStack Start app. Use when the app needs to store or query data, persist state, or keep per-user data. Triggers on "database", "Postgres", "Neon", "save data", "store data", "persist", "tables", "SQL", "query", "migrations".

evalix098/tiktoklive

Share-link previews and app identity for apps on *.grok.me: the injector-owned og:image card, the SVG favicon, and PWA icons for installable apps. Use when scaffolding, renaming, or restyling the app — and for share / unfurl / OG / Twitter card questions. A custom 1200×630 card from the app's own art is the default — games of every kind (DOM board/word games included), whimsical apps, creative tools, and brand-forward pages; only plain utilities keep the placeholder. Always run the brand-asset pass as a `task` subagent and never wait for it. Triggers on "share", "rename", "app name", "OG", "Open Graph", "twitter card", "unfurl", "og:image", "og:type", "x:game:image", "x-banner", "link preview", "social card", "thumbnail", "preview image", "favicon", "app icon", "PWA", "manifest", "installable", "home screen", "SEO", "meta description".

evalix098/tiktoklive

Official Three.js API and TSL (Three.js Shading Language) reference for LLM code generation. Load when writing or debugging three.js / WebGL / WebGPU / custom materials / shaders / GLTF / advanced three APIs beyond basic game loop/controls. Prefer building-games for game correctness (loop, WASD, camera, orientation); use this skill for full API/TSL depth. Triggers on "three.js", "threejs", "WebGPU", "TSL", "NodeMaterial", "shader", "GLTF", "MeshStandard", "OrbitControls", "WebGLRenderer".

evalix098/tiktoklive

Grok Build only. Turn a 2D character still into denser animation sprites via imagine_text_to_image base → imagine_image_to_video (6s/10s run-in-place) → ffmpeg frames → magenta chroma-key → dense sampled strips/grids/GIFs. Use when the user wants video-to-sprite, smoother run/walk cycles, or denser intermediate poses. Prefer generate2dsprite for crisp production pixel sheets. Triggers on "video to sprite", "imagine_image_to_video sprite", "dense walk cycle", "smooth run animation from video".

evalix098/tiktoklive

Call the xAI API (Grok) from this app's server code using the injected XAI_API_KEY: chat/LLM features, image and video generation (Imagine), and voice (text-to-speech). Use when the app needs any "AI" / "assistant" / "chatbot" / "Grok" functionality, runtime image/video generation, or speech. Triggers on "AI", "LLM", "chatbot", "assistant", "Grok", "xAI", "generate text", "summarize", "generate image", "AI video", "voice", "text to speech", "TTS", "OpenAI" (use xAI instead).

相关技能