Add Usesend but havent tested it just yet

This commit is contained in:
2025-09-23 07:41:39 -05:00
parent 4fe32474df
commit 70924f84a9
11 changed files with 510 additions and 187 deletions

View 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)
},
});