feat: delete all sessions if password was changed

This commit is contained in:
Elias Schneider
2023-01-10 13:32:37 +01:00
parent 74e8956106
commit 02e41e2437
3 changed files with 59 additions and 20 deletions

View File

@@ -87,10 +87,16 @@ export class AuthService {
const hash = await argon.hash(newPassword);
return await this.prisma.user.update({
await this.prisma.refreshToken.deleteMany({
where: { userId: user.id },
});
await this.prisma.user.update({
where: { id: user.id },
data: { password: hash },
});
return this.createRefreshToken(user.id);
}
async createAccessToken(user: User, refreshTokenId: string) {
@@ -112,7 +118,12 @@ export class AuthService {
refreshTokenId: string;
};
await this.prisma.refreshToken.delete({ where: { id: refreshTokenId } });
await this.prisma.refreshToken
.delete({ where: { id: refreshTokenId } })
.catch((e) => {
// Ignore error if refresh token doesn't exist
if (e.code != "P2025") throw e;
});
}
async refreshAccessToken(refreshToken: string) {