* Handle Stripe logic in `paymentCallback` * Remove endpoint * Do not send email verification email if premium username * Remove logic from verify-view * Callback send verification email * Add `create` method to `VerificationToken` repository * Create `VerificationTokenService` * Early return if payment failed * Refactor token generation * Add tests * Type fixes * Type fixes
17 lines
550 B
TypeScript
17 lines
550 B
TypeScript
import { randomBytes, createHash } from "crypto";
|
|
|
|
import { VerificationTokenRepository } from "../repository/verificationToken";
|
|
|
|
export class VerificationTokenService {
|
|
static async create({ identifier, expires }: { identifier: string; expires: Date }) {
|
|
const token = randomBytes(32).toString("hex");
|
|
const hashedToken = createHash("sha256")
|
|
.update(`${token}${process.env.NEXTAUTH_SECRET}`)
|
|
.digest("hex");
|
|
|
|
await VerificationTokenRepository.create({ identifier, token: hashedToken, expires });
|
|
|
|
return token;
|
|
}
|
|
}
|