Skip to content

Commit

Permalink
fix compilation errors (webstorm's incremental TS compilation doesn't…
Browse files Browse the repository at this point in the history
… notice prisma schema changes..)
  • Loading branch information
realmayus committed Oct 10, 2024
1 parent d38bd8c commit e1f5c90
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion common/secret/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function getSecrets(user: User): Promise<object[]> {
userId: user.userID,
OR: [{ expiresAt: null }, { expiresAt: { gte: new Date() } }],
},
select: { createdAt: true, expiresAt: true, id: true, lastUsed: true, type: true, userId: true, description: true, deviceId: true },
select: { createdAt: true, expiresAt: true, id: true, lastUsed: true, type: true, userId: true, description: true, lastUsedDeviceId: true },
});

logger.info(`User(${user.userID}) retrieved ${result.length} secrets`);
Expand Down
8 changes: 4 additions & 4 deletions common/secret/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function createToken(
expiresAt,
lastUsed: null,
description,
deviceId,
lastUsedDeviceId: deviceId,
},
});

Expand Down Expand Up @@ -140,10 +140,10 @@ export async function loginToken(token: string, deviceId: string): Promise<User
// but only expire it soon to not reduce the possibility that eavesdroppers use the token
const inOneHour = new Date();
inOneHour.setHours(inOneHour.getHours() + 1);
await prisma.secret.update({ where: { id: secret.id }, data: { expiresAt: inOneHour, lastUsed: new Date(), deviceId } });
await prisma.secret.update({ where: { id: secret.id }, data: { expiresAt: inOneHour, lastUsed: new Date(), lastUsedDeviceId: deviceId } });
logger.info(`User(${user.userID}) logged in with email token Secret(${secret.id}), token will be revoked in one hour`);
} else {
await prisma.secret.update({ data: { lastUsed: new Date(), deviceId }, where: { id: secret.id } });
await prisma.secret.update({ data: { lastUsed: new Date(), lastUsedDeviceId: deviceId }, where: { id: secret.id } });
logger.info(`User(${user.userID}) logged in with email token Secret(${secret.id}) it will expire at ${secret.expiresAt.toISOString()}`);
}

Expand All @@ -160,7 +160,7 @@ export async function loginToken(token: string, deviceId: string): Promise<User
logger.info(`User(${user.userID}) changed their email to ${newEmail} via email token login`);
}
} else {
await prisma.secret.update({ data: { lastUsed: new Date(), deviceId }, where: { id: secret.id } });
await prisma.secret.update({ data: { lastUsed: new Date(), lastUsedDeviceId: deviceId }, where: { id: secret.id } });
logger.info(`User(${user.userID}) logged in with persistent token Secret(${secret.id})`);
}

Expand Down
5 changes: 3 additions & 2 deletions graphql/secret/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ export class MutateSecretResolver {
let tokenId = id;
let deviceId = undefined;
if (id) {
deviceId = (await prisma.secret.findUnique({ where: { id: tokenId } })).deviceId;
deviceId = (await prisma.secret.findUnique({ where: { id: tokenId } })).lastUsedDeviceId;
} else if (token) {
deviceId = (await getSecretByToken(token)).deviceId;
deviceId = (await getSecretByToken(token)).lastUsedDeviceId;
console.log('hi');
} else {
throw new UserInputError(`Either the id or the token must be passed`);
}
Expand Down

0 comments on commit e1f5c90

Please sign in to comment.