Skip to content

Commit

Permalink
fix(token): limit user update query to 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerald Baulig committed Aug 19, 2024
1 parent 95759af commit 6dc0397
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/token_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ export class TokenService implements TokenServiceImplementation {
field: 'id',
operation: Filter_Operation.eq,
value: payload?.accountId
}]
}],
limit: 1
}];
const userData = await this.userService.superRead(ReadRequest.fromPartial({ filters }), {});
if (userData?.items?.length > 0) {
let user = userData.items[0].payload;
const user = await this.userService.superRead(
ReadRequest.fromPartial({ filters }), {}
).then(
response => response.items?.[0]?.payload
);
if (user) {
const expiredTokenList = user?.tokens?.length > 0 && user.tokens.filter(
obj => obj?.expires_in && (obj.expires_in.getTime() < new Date().getTime())
);
Expand All @@ -77,7 +81,7 @@ export class TokenService implements TokenServiceImplementation {
}
const token = {
name: token_name,
expires_in: tokenData?.expires_in, // since AQL is used to store to DB
expires_in: tokenData?.expires_in,
token: payload.jti,
type,
interactive: true,
Expand Down

0 comments on commit 6dc0397

Please sign in to comment.