Skip to content

Commit

Permalink
fix: get user_info incorrectly who issued by oidc provider
Browse files Browse the repository at this point in the history
  • Loading branch information
ChingCdesu committed Sep 30, 2023
1 parent e2634f5 commit a8d40a7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "supernode",
"version": "1.0.0-alpha.8",
"version": "1.0.0-alpha.9",
"description": "",
"author": "",
"private": true,
Expand Down
7 changes: 6 additions & 1 deletion src/modules/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ export class UserControllerV1 {
@UseGuards(AuthenticatedGuard)
@Get('me')
async me(@Req() req: Request) {
return req.user;
if (req.user instanceof UserModel) {
return req.user;
} else if (req.user?.sub /* OIDC */) {
return await this._userService.getByUniqueId(req.user.sub);
}
return {};
}

@ApiOperation({ summary: '更新自己的用户信息' })
Expand Down
12 changes: 12 additions & 0 deletions src/modules/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ export class UserService extends LoggerProvider {
return user;
}

public async getByUniqueId(uniqueId: string): Promise<UserModel> {
const user = await this._userModel.findOne({
where: {
uniqueId,
},
});
if (isNull(user)) {
throw new NotFoundException('User not found');
}
return user;
}

public async create(createUserDto: CreateUserDto): Promise<UserModel> {
const user = await this._userModel.create(Object.assign(createUserDto));
const operator = this._req.user;
Expand Down

0 comments on commit a8d40a7

Please sign in to comment.