feat(cli): add shumai-cli and token authentication

This commit is contained in:
yiling
2026-06-21 12:35:12 +08:00
parent e33cbdb37c
commit 90ef063d43
40 changed files with 3609 additions and 18 deletions
+38
View File
@@ -0,0 +1,38 @@
import { prisma } from '@shumai/db'
export class ApiTokenService {
async listTokens(userId: string) {
return prisma.apiToken.findMany({
where: { userId },
orderBy: { id: 'desc' },
})
}
async createToken(userId: string, name: string) {
return prisma.apiToken.create({
data: {
userId,
name,
},
})
}
async deleteToken(userId: string, tokenId: string) {
return prisma.apiToken.delete({
where: {
id: tokenId,
userId,
},
})
}
async validateToken(tokenString: string) {
const apiToken = await prisma.apiToken.findUnique({
where: { token: tokenString },
include: { user: true },
})
return apiToken ? apiToken.user : null
}
}
export const apiTokenService = new ApiTokenService()