feat: add CNB login functionality and user management
- Introduced `cnb-login` route to handle user login via CNB token. - Created `CnbServices` class for managing CNB user interactions. - Added `findByCnbId` method in the User model to retrieve users by CNB ID. - Updated error handling to provide more structured error messages. - Enhanced user creation logic to handle CNB users. - Added tests for the new CNB login functionality.
This commit is contained in:
@@ -6,12 +6,21 @@ import jsonwebtoken from 'jsonwebtoken';
|
||||
|
||||
import { redis } from '@/app.ts';
|
||||
import { createCookie, clearCookie } from './me.ts';
|
||||
import z from 'zod';
|
||||
|
||||
app
|
||||
.route({
|
||||
path: 'user',
|
||||
key: 'webLogin',
|
||||
description: 'web登录接口,配合插件使用',
|
||||
middleware: [authCan],
|
||||
metadata: {
|
||||
args: {
|
||||
loginToken: z.string().describe('web登录令牌,服务端生成,客户端保持一致'),
|
||||
sign: z.string().describe('签名,服务端生成,客户端保持一致'),
|
||||
randomId: z.string().describe('随机字符串,服务端和客户端保持一致'),
|
||||
}
|
||||
}
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
@@ -97,6 +106,7 @@ app
|
||||
.route({
|
||||
path: 'user',
|
||||
key: 'checkLoginStatus',
|
||||
description: '循环检查登陆状态',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const { loginToken } = ctx.query;
|
||||
|
||||
Reference in New Issue
Block a user