Add Usesend but havent tested it just yet
This commit is contained in:
28
packages/backend/convex/custom/auth/password/reset.ts
Normal file
28
packages/backend/convex/custom/auth/password/reset.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Usesend } from '..';
|
||||
import { UseSend } from 'usesend-js';
|
||||
import { generateRandomString, RandomReader } from '@oslojs/crypto/random';
|
||||
|
||||
export const UsesendOTPPasswordReset = Usesend({
|
||||
id: 'unsend-otp',
|
||||
apiKey: process.env.AUTH_USESEND_API_KEY,
|
||||
async generateVerificationToken() {
|
||||
const random: RandomReader = {
|
||||
read(bytes) {
|
||||
crypto.getRandomValues(bytes);
|
||||
},
|
||||
};
|
||||
const alphabet = '0123456789';
|
||||
const length = 8;
|
||||
return generateRandomString(random, alphabet, length);
|
||||
},
|
||||
async sendVerificationRequest({ identifier: email, provider, token }) {
|
||||
const useSend = new UseSend(provider.apiKey, 'https://usesend.gbrown.org');
|
||||
const { error } = await useSend.emails.send({
|
||||
to: [email],
|
||||
from: provider.from ?? 'TechTracker Admin <admin@mail.techtracker.gbrown.org>',
|
||||
subject: `Reset your password - TechTracker`,
|
||||
text: `Your password reset code is ${token}`,
|
||||
});
|
||||
if (error) throw new Error("Usesend error: " + error.message)
|
||||
},
|
||||
});
|
Reference in New Issue
Block a user