This commit is contained in:
tianmo committed 2026-09-29 20:59:35 +08:00
1 parent 6ae4c109ce
commit ea6c080d89
2 files changed
+34 -2

No files matched your search

+10
View File
@@ -158,6 +158,16 @@ Images/Placeholder/defaultAvatar.png
Images/Placeholder/weixin.png
```
这三张图是**必需的**,缺了会导致「我的」页头像位、「登录」页背景显示为裂图。
验证:
```bash
curl -o /dev/null -s -w "%{http_code}\n" https://<数据域名>/Images/Placeholder/user.png
curl -o /dev/null -s -w "%{http_code}\n" https://<数据域名>/Images/Placeholder/weixin.png
```
两条都返回 `200` 才算就绪。
**目录名与文件名不可更改**,前端是拼路径访问的。完整约定见
[`yelaymaths_data.yeomai.site/README.md`](../yelaymaths_data.yeomai.site/README.md)。
@@ -3,6 +3,7 @@ import { JwtService } from '@nestjs/jwt';
import { APP_CONFIG, type AppConfig } from '../../config/config';
import { encryptSecret } from '../../common/crypto';
import { AppError } from '../../common/errors';
import { staticUrls } from '../../common/urls';
import { PrismaService } from '../../prisma/prisma.service';
import { WechatService } from './wechat.service';
@@ -10,10 +11,23 @@ import { WechatService } from './wechat.service';
export const ACCESS_TTL = '2h' as const;
export const REFRESH_TTL = '30d' as const;
/**
* 登录返回的用户信息。
*
* 字段必须与 GET /v1/me 保持一致(尤其是 headiconUrl)——
* 小程序启动时只调登录接口,若这里少字段,页面读到的就是残缺的 user,
* 头像会退回占位图,直到用户手动点一次登录调了 /v1/me 才恢复。
*/
export interface LoginResult {
accessToken: string;
refreshToken: string;
user: { id: number; nickname: string | null; headiconId: number; isNew: boolean };
user: {
id: number;
nickname: string | null;
headiconId: number;
headiconUrl: string | null;
isNew: boolean;
};
}
@Injectable()
@@ -55,7 +69,15 @@ export class AuthService {
return {
accessToken: await this.sign(user.id, 'user', ACCESS_TTL, this.cfg.JWT_ACCESS_SECRET),
refreshToken: await this.sign(user.id, 'user', REFRESH_TTL, this.cfg.JWT_REFRESH_SECRET),
user: { id: user.id, nickname: user.nickname, headiconId: user.headicon_id, isNew: !existing },
user: {
id: user.id,
nickname: user.nickname,
headiconId: user.headicon_id,
// 与 /v1/me 的规则一致:0 表示未设置,交给前端用占位图
headiconUrl:
user.headicon_id > 0 ? staticUrls.headicon(this.cfg.STATIC_BASE_URL, user.headicon_id) : null,
isNew: !existing,
},
};
}