-
-
Save dipzera/684a99744c3393931c56e5474b2162a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async logout(userId: string): Promise<void> { | |
await this.prisma.user.update({ | |
where: { | |
id: userId, | |
}, | |
data: { | |
hashedRefreshToken: null | |
}, | |
}); | |
} | |
async refresh(userId: string, refreshToken: string): Promise<Tokens> { | |
const user = await this.prisma.user.findUnique({ | |
where: { | |
id: userId, | |
}, | |
}); | |
if (!user) { | |
throw new ForbiddenException('Access denied'); | |
} | |
const tokenMatches = await bcrypt.compare(refreshToken, user.hashedRefreshToken); | |
// The token is invalid and we can't issue a pair of new tokens | |
if (!tokenMatches) { | |
throw new ForbiddenException('Access denied'); | |
} | |
const tokens = this.signTokens(user.id, user.email); | |
await this.updateRefreshToken(user.id, tokens.refreshToken); | |
return tokens; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment