Skip to content

Commit

Permalink
resolving a runtime with access token verification
Browse files Browse the repository at this point in the history
  • Loading branch information
Baalmart committed Jan 26, 2025
1 parent 6a808a5 commit 8751753
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/auth-service/models/AccessToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const AccessTokenSchema = new mongoose.Schema(
required: [true, "token is required!"],
},
last_used_at: { type: Date },
last_ip_address: { type: Date },
last_ip_address: { type: String },
expires_in: { type: Number },
expires: {
type: Date,
Expand Down
20 changes: 13 additions & 7 deletions src/auth-service/utils/token.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -771,10 +771,14 @@ const token = {
const endTime = process.hrtime.bigint();
const latency = calculateLatency(startTime, endTime);

await AccessTokenModel("airqo").updateOne(
{ token },
{ $set: { last_used_at: new Date(), last_ip_address: ip } }
);
try {
await AccessTokenModel("airqo").updateOne(
{ token },
{ $set: { last_used_at: new Date(), last_ip_address: ip } }
);
} catch (updateError) {
logger.error(`Error updating AccessToken: ${updateError.message}`);
}
const logPayload = {
timestamp: new Date().toISOString(),
token: accessToken.token,
Expand All @@ -786,10 +790,12 @@ const token = {
latency: latency,
};

if (constants.ENVIRONMENT === "PRODUCTION ENVIRONMENT") {
try {
await logAPIUsage(logPayload);
apiUsageLogger.info(stringify(logPayload));
} catch (loggingError) {
logger.error(`Error logging API Usage: ${loggingError.message}`);
}
await logAPIUsage(logPayload);
apiUsageLogger.info(stringify(logPayload)); // Log to stdout (for BigQuery)

return createValidTokenResponse();
}
Expand Down

0 comments on commit 8751753

Please sign in to comment.