29 lines
1023 B
TypeScript
29 lines
1023 B
TypeScript
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)
|
|
},
|
|
});
|