Skip to content

Commit 966ffc2

Browse files
committed
fix: throw trpc error if unable to delete
since we pass all the checks, if we can't delete the token, we just throw a trpc error to feedabck to the user
1 parent 5a59282 commit 966ffc2

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

apps/web/src/server/modules/auth/auth.service.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,19 @@ export const emailVerifyOtp = async ({
119119
.deleteFrom('VerificationToken')
120120
.where('identifier', '=', vfnIdentifier)
121121
.returningAll()
122-
.executeTakeFirstOrThrow()
122+
.executeTakeFirstOrThrow(
123+
// NOTE: If we are unable to find the token,
124+
// this means that it has been deleted between
125+
// our initial query and the deletion here
126+
() =>
127+
new TRPCError({
128+
code: 'BAD_REQUEST',
129+
message:
130+
'Token is invalid or has expired. Please request a new OTP.',
131+
}),
132+
)
123133
} catch (error) {
124-
// see error code here: https://www.prisma.io/docs/reference/api-reference/error-reference#p2025
134+
// see error code here: https://www.prisma.io/docs/orm/reference/error-reference#p2025
125135
if (
126136
error instanceof Prisma.PrismaClientKnownRequestError &&
127137
error.code === 'P2025'

0 commit comments

Comments
 (0)