Skip to content

Commit

Permalink
merge: branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
virtual-designer committed Sep 20, 2024
2 parents c0a4588 + bf9cf2e commit 00f1d8d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/main/typescript/api/controllers/AuthController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ class AuthController extends Controller {
});
}

const token = await this.authService.provisionToken(user);

const guilds: APIGuild[] = [];

for (const guildId of user.guilds) {
Expand All @@ -225,7 +227,7 @@ class AuthController extends Controller {
discordId: user.discordId,
avatar: avatarURL
},
token: user.token,
token,
expires: user.tokenExpiresAt?.getTime(),
guilds
};
Expand Down
15 changes: 11 additions & 4 deletions src/main/typescript/services/AuthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,17 @@ class AuthService extends Service {
};
}

await this.provisionToken(user);

return {
success: true,
user
};
}

public async provisionToken(user: User) {
if (!user.token || !user.tokenExpiresAt || user.tokenExpiresAt.getTime() <= Date.now()) {
this.application.logger.debug(`Provisioning token for user ${user.username}`);
const token = this.generateToken(user);
const tokenExpiresAt = new Date(Date.now() + 48 * 60 * 60 * 1000);

Expand All @@ -77,10 +87,7 @@ class AuthService extends Service {
user.tokenExpiresAt = tokenExpiresAt;
}

return {
success: true,
user
};
return user.token;
}
}

Expand Down

0 comments on commit 00f1d8d

Please sign in to comment.