All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 1m0s
- AI: 新三层架构 Provider→Gateway→Workflow(15文件,DeepSeek+MiniMax) - Auth: 全局JwtAuthGuard + @Public()装饰器白名单路由 - DB: 12个Repository从Map/Array迁到Prisma - Schema: 新增AiUsageLog、WaitlistEntry模型 - API: /api-docs-json加Basic Auth保护 - 清理: 删除infrastructure/ai、docs/旧文档 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
27 lines
787 B
TypeScript
27 lines
787 B
TypeScript
import * as crypto from 'crypto';
|
|
import { Injectable } from '@nestjs/common';
|
|
import { JwtService } from '@nestjs/jwt';
|
|
|
|
@Injectable()
|
|
export class TokenService {
|
|
constructor(private readonly jwtService: JwtService) {}
|
|
|
|
generateAccessToken(user: { id: string; email?: string | null; role?: string | null }): Promise<string> {
|
|
return this.jwtService.signAsync({
|
|
sub: user.id,
|
|
email: user.email,
|
|
role: user.role,
|
|
});
|
|
}
|
|
|
|
generateRefreshToken(): { token: string; hash: string } {
|
|
const token = crypto.randomBytes(48).toString('hex');
|
|
const hash = crypto.createHash('sha256').update(token).digest('hex');
|
|
return { token, hash };
|
|
}
|
|
|
|
hashToken(token: string): string {
|
|
return crypto.createHash('sha256').update(token).digest('hex');
|
|
}
|
|
}
|