feat: 增加开发模式 URL 免登录

- 新增 dev-only 且仅限本机访问的 admin 免登入口

- 管理端支持通过 ?devLogin=admin 自动换取登录态并清理 URL 参数

- 删除未受保护的临时 token 接口并补充关键单测
This commit is contained in:
2026-03-07 18:16:42 +08:00
parent 37e185e74a
commit a93f7ca216
14 changed files with 459 additions and 96 deletions

View File

@@ -0,0 +1,57 @@
import { describe, expect, it } from 'vitest';
import {
getDevLoginAccount,
removeDevLoginQuery,
shouldAttemptDevLogin,
} from '../dev-login';
describe('dev-login route helpers', () => {
it('reads the admin account from the query string', () => {
expect(getDevLoginAccount({ devLogin: 'admin' })).toBe('admin');
expect(getDevLoginAccount({ devLogin: ['admin', 'other'] })).toBe('admin');
expect(getDevLoginAccount({ devLogin: ' ' })).toBeNull();
});
it('removes only the devLogin query parameter', () => {
expect(
removeDevLoginQuery({
devLogin: 'admin',
redirect: '/ai/workflow',
}),
).toEqual({
redirect: '/ai/workflow',
});
});
it('attempts dev login only in dev mode and without an existing token', () => {
expect(
shouldAttemptDevLogin({
account: 'admin',
hasAccessToken: false,
isDev: true,
}),
).toBe(true);
expect(
shouldAttemptDevLogin({
account: 'admin',
hasAccessToken: true,
isDev: true,
}),
).toBe(false);
expect(
shouldAttemptDevLogin({
account: 'guest',
hasAccessToken: false,
isDev: true,
}),
).toBe(false);
expect(
shouldAttemptDevLogin({
account: 'admin',
hasAccessToken: false,
isDev: false,
}),
).toBe(false);
});
});