Update stuff so we can pass build hopefully
This commit is contained in:
@@ -1,39 +1,7 @@
|
|||||||
import type { EmailConfig, EmailUserConfig } from '@auth/core/providers/email';
|
import type { EmailConfig, EmailUserConfig } from '@auth/core/providers/email';
|
||||||
import { generateRandomString, RandomReader } from '@oslojs/crypto/random';
|
import { generateRandomString, RandomReader } from '@oslojs/crypto/random';
|
||||||
import { alphabet } from 'oslo/crypto';
|
import { alphabet } from 'oslo/crypto';
|
||||||
|
import { UseSend } from 'usesend-js';
|
||||||
type UseSendEmailPayload = {
|
|
||||||
from: string;
|
|
||||||
to: string[];
|
|
||||||
subject: string;
|
|
||||||
text: string;
|
|
||||||
html: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
const sendUseSendEmail = async (
|
|
||||||
apiKey: string,
|
|
||||||
useSendUrl: string,
|
|
||||||
payload: UseSendEmailPayload,
|
|
||||||
) => {
|
|
||||||
const response = await fetch(`${useSendUrl}/api/v1/emails`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${apiKey}`,
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(payload),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
let errorBody: unknown;
|
|
||||||
try {
|
|
||||||
errorBody = await response.json();
|
|
||||||
} catch {
|
|
||||||
errorBody = response.statusText;
|
|
||||||
}
|
|
||||||
throw new Error(`UseSend error: ${JSON.stringify(errorBody)}`);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function UseSendProvider(config: EmailUserConfig): EmailConfig {
|
export default function UseSendProvider(config: EmailUserConfig): EmailConfig {
|
||||||
return {
|
return {
|
||||||
@@ -64,11 +32,13 @@ export default function UseSendProvider(config: EmailUserConfig): EmailConfig {
|
|||||||
throw new Error('USESEND_API_KEY and USESEND_URL must be set.');
|
throw new Error('USESEND_API_KEY and USESEND_URL must be set.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const useSend = new UseSend(apiKey, useSendUrl);
|
||||||
|
|
||||||
// For password reset, we want to send the code, not the magic link
|
// For password reset, we want to send the code, not the magic link
|
||||||
const isPasswordReset =
|
const isPasswordReset =
|
||||||
url.includes('reset') || provider.id.includes('reset');
|
url.includes('reset') || provider.id.includes('reset');
|
||||||
|
|
||||||
await sendUseSendEmail(apiKey, useSendUrl, {
|
const result = await useSend.emails.send({
|
||||||
from: provider.from ?? 'noreply@example.com',
|
from: provider.from ?? 'noreply@example.com',
|
||||||
to: [to],
|
to: [to],
|
||||||
subject: isPasswordReset
|
subject: isPasswordReset
|
||||||
@@ -100,6 +70,10 @@ export default function UseSendProvider(config: EmailUserConfig): EmailConfig {
|
|||||||
</div>
|
</div>
|
||||||
`,
|
`,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (result.error) {
|
||||||
|
throw new Error('UseSend error: ' + JSON.stringify(result.error));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
options: config,
|
options: config,
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ has_cloud_deployment_env() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if has_self_hosted_env || has_cloud_deployment_env; then
|
if has_self_hosted_env || has_cloud_deployment_env; then
|
||||||
|
cd "$ROOT_DIR"
|
||||||
|
bun patch:usesend
|
||||||
cd "$ROOT_DIR/packages/backend"
|
cd "$ROOT_DIR/packages/backend"
|
||||||
bun run codegen
|
bun run codegen
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
Reference in New Issue
Block a user