mirror of
https://github.com/bubblecup-12/VogelSocialMedia.git
synced 2025-07-09 12:08:47 +00:00
added refreshtoken logic to backend
This commit is contained in:
parent
a9bda19891
commit
ae318b61bf
2 changed files with 29 additions and 0 deletions
19
code/backend/src/tasks/deleteTokens.ts
Normal file
19
code/backend/src/tasks/deleteTokens.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { PrismaClient } from "../../prisma/app/generated/prisma/client";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export const deleteExpiredTokens = async () => {
|
||||
const now = new Date();
|
||||
try {
|
||||
const result = await prisma.refreshToken.deleteMany({
|
||||
where: {
|
||||
expiresAt: {
|
||||
lt: now, // delete expired tokens
|
||||
},
|
||||
},
|
||||
});
|
||||
console.log(`deleted ${result.count} tokens`);
|
||||
} catch (error) {
|
||||
console.error("Error while deleting tokens:", error);
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue