mx-core-local-auth
GitHub在本地开发环境中,当UI或API验证遇到登录门控时,通过操作PostgreSQL数据库创建临时的所有者会话以绕过认证,并在验证完成后立即清理。
Trigger Scenarios
Install
npx skills add mx-space/core --skill mx-core-local-auth -g -y
SKILL.md
Frontmatter
{
"name": "mx-core-local-auth",
"description": "Create and reuse a short-lived local mx-core owner session when UI or API verification encounters a login gate, redirect, 401, or AUTH_NOT_LOGGED_IN response. Use only against the local development database and remove the temporary session after verification."
}
Local authentication during verification
Treat authentication as an on-demand branch of the verification being performed.
- Attempt the exact UI or API operation that needs verification.
- If it succeeds anonymously, continue without creating authentication state.
- If it fails on authentication, create one short-lived owner session directly
in the local PostgreSQL
sessionstable. - Reuse that session for the original operation, collect the required evidence, and delete the session immediately afterward.
Create the temporary session
Use the repository's configured local PG_URL; do not assume a container name or
hard-code database credentials. Generate a unique session ID and a high-entropy
token without a . character. Insert a session that expires in at most 15 minutes:
WITH target AS (
SELECT r.id, a.provider_id
FROM readers AS r
JOIN accounts AS a ON a.user_id = r.id
WHERE r.role = 'owner'
ORDER BY r.created_at
LIMIT 1
)
INSERT INTO sessions (id, user_id, token, expires_at, provider)
SELECT '<session-id>', id, '<session-token>', now() + interval '15 minutes', provider_id
FROM target;
Fail if no owner account was selected or the insert did not create exactly one row. Do not create or modify a reader, account, password, or API key.
Reuse the session
- For API verification, send the raw token as
Authorization: Bearer <session-token>. The enabled Better Authbearer()plugin signs it internally and resolves the matching database session. - For browser UI verification, sign the token with the local
JWT_SECRETusing HMAC-SHA256 with standard Base64 output, then setbetter-auth.session_token=<token>.<signature>in the same browser context used for evidence. Let the browser cookie API encode the value; when writing a rawCookieheader, URL-encode it first. Never print the secret, token, or cookie.
Retry the exact protected operation rather than adding a separate authentication
test. Local development routes have no /api/v1 prefix.
Cleanup and boundaries
Delete the temporary row by both ID and token in a finally-style cleanup, even
when verification fails. This workflow is forbidden for staging, production,
shared databases, or any database whose local ownership is uncertain.
Version History
- c2ffb56 Current 2026-08-19 23:55


