feat: wechat login

This commit is contained in:
ilhamtahir committed 2024-11-18 19:19:58 +08:00
1 parent 3283d94ea4
commit 3cb55e20d5
13 files changed
+181 -12

No files matched your search

+5
View File
@@ -5,6 +5,7 @@ import { CreateTokenRequest } from '../dto/create-token.request';
import * as bcrypt from 'bcrypt';
import { TokenVo } from '../vo/token.vo';
import { JWT_SECRET } from '../constants/jwt';
import { User } from '../entity/user.entity';
@Injectable()
export class AuthService {
@@ -30,6 +31,10 @@ export class AuthService {
if (!isPasswordValid) {
throw new UnauthorizedException('用户名或密码错误');
}
return await this.generateToken(user);
}
async generateToken(user: User) {
const payload = { sub: user.id, username: user.username }; // payload 中包含用户 ID 和用户名
const tokenVo = new TokenVo();
try {