Skip to content

Commit a979dc3

Browse files
authored
fix(authentication): UserLogin, GetTeam RPCs (#1128)
* fix(authentication): TokenProvider.createUserTokens() not throwing for inactive users * fix(authentication): Authentication.UserLogin RPC not throwing for inactive users * fix(authentication): Authentication.GetTeam RPC not-found returning improperly initialized objects
1 parent e76bfea commit a979dc3

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

modules/authentication/src/Authentication.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,26 @@ export default class Authentication extends ManagedModule<Config> {
226226
message: 'User not found',
227227
});
228228
}
229+
if (!user.active) {
230+
return callback({
231+
code: status.PERMISSION_DENIED,
232+
message: 'User is blocked or deleted',
233+
});
234+
}
229235
const config = ConfigController.getInstance().config;
230236

231-
const tokens = await TokenProvider.getInstance().provideUserTokensInternal({
232-
user,
233-
clientId,
234-
config,
235-
});
237+
const tokens = await TokenProvider.getInstance()
238+
.provideUserTokensInternal({
239+
user,
240+
clientId,
241+
config,
242+
})
243+
.catch(() => {
244+
return callback({
245+
code: status.INTERNAL,
246+
message: 'Failed to login',
247+
});
248+
});
236249

237250
return callback(null, {
238251
accessToken: tokens.accessToken,
@@ -417,7 +430,12 @@ export default class Authentication extends ManagedModule<Config> {
417430
async getTeam(call: GrpcRequest<GetTeamRequest>, callback: GrpcCallback<GrpcTeam>) {
418431
const request = createParsedRouterRequest(call.request);
419432
try {
420-
const team = (await new TeamsAdmin(this.grpcSdk).getTeam(request)) as models.Team;
433+
const team = (await new TeamsAdmin(this.grpcSdk).getTeam(request)) as
434+
| models.Team
435+
| undefined;
436+
if (!team) {
437+
return callback({ code: status.NOT_FOUND, message: 'Team not found' });
438+
}
421439
return callback(null, {
422440
id: team._id,
423441
name: team.name,

modules/authentication/src/handlers/tokenProvider.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ export class TokenProvider {
144144
private async createUserTokens(
145145
tokenOptions: TokenOptions,
146146
): Promise<[AccessToken, RefreshToken?]> {
147+
if (!tokenOptions.user.active) {
148+
throw new Error('User is blocked or deleted');
149+
}
147150
const signTokenOptions: SignOptions = {
148151
expiresIn: (tokenOptions.config.accessTokens.expiryPeriod as number) / 1000,
149152
};

0 commit comments

Comments
 (0)