feat: expo plugin (#375)

This commit is contained in:
Bereket Engida
2024-11-01 09:24:14 +03:00
committed by GitHub
parent 979923d05e
commit cce28070ee
87 changed files with 10116 additions and 2059 deletions

View File

@@ -12,28 +12,68 @@ import {
import { reactInvitationEmail } from "./email/invitation";
import { reactResetPasswordEmail } from "./email/rest-password";
import { resend } from "./email/resend";
import { expo } from "@better-auth/expo";
const from = process.env.BETTER_AUTH_EMAIL || "delivered@resend.dev";
const to = process.env.TEST_EMAIL || "";
const database = new Database("better-auth.sqlite");
const twoFactorPlugin = twoFactor({
otpOptions: {
async sendOTP(user, otp) {
await resend.emails.send({
from,
to: user.email,
subject: "Your OTP",
html: `Your OTP is ${otp}`,
});
},
},
});
const organizationPlugin = organization({
async sendInvitationEmail(data) {
const res = await resend.emails.send({
from,
to: data.email,
subject: "You've been invited to join an organization",
react: reactInvitationEmail({
username: data.email,
invitedByUsername: data.inviter.user.name,
invitedByEmail: data.inviter.user.email,
teamName: data.organization.name,
inviteLink:
process.env.NODE_ENV === "development"
? `http://localhost:3000/accept-invitation/${data.id}`
: `https://${
process.env.NEXT_PUBLIC_APP_URL ||
process.env.VERCEL_URL ||
process.env.BETTER_AUTH_URL
}/accept-invitation/${data.id}`,
}),
});
console.log(res, data.email);
},
});
export const auth = betterAuth({
database,
emailVerification: {
async sendVerificationEmail(user, url) {
console.log("Sending verification email to", user.email);
const res = await resend.emails.send({
from,
to: to || user.email,
subject: "Verify your email address",
html: `<a href="${url}">Verify your email address</a>`,
});
console.log(res, user.email);
// const res = await resend.emails.send({
// from,
// to: to || user.email,
// subject: "Verify your email address",
// html: `<a href="${url}">Verify your email address</a>`,
// });
// console.log(res, user.email);
},
sendOnSignUp: true,
},
account: {
enabled: true,
accountLinking: {
trustedProviders: ["google", "github"],
},
@@ -60,7 +100,8 @@ export const auth = betterAuth({
google: {
clientId: process.env.GOOGLE_CLIENT_ID || "",
clientSecret: process.env.GOOGLE_CLIENT_SECRET || "",
accessType: "offline",
// accessType: "offline",
// prompt: "select_account",
},
discord: {
clientId: process.env.DISCORD_CLIENT_ID || "",
@@ -76,46 +117,14 @@ export const auth = betterAuth({
},
},
plugins: [
organization({
async sendInvitationEmail(data) {
const res = await resend.emails.send({
from,
to: data.email,
subject: "You've been invited to join an organization",
react: reactInvitationEmail({
username: data.email,
invitedByUsername: data.inviter.user.name,
invitedByEmail: data.inviter.user.email,
teamName: data.organization.name,
inviteLink:
process.env.NODE_ENV === "development"
? `http://localhost:3000/accept-invitation/${data.id}`
: `https://${
process.env.NEXT_PUBLIC_APP_URL ||
process.env.VERCEL_URL ||
process.env.BETTER_AUTH_URL
}/accept-invitation/${data.id}`,
}),
});
console.log(res, data.email);
},
}),
twoFactor({
otpOptions: {
async sendOTP(user, otp) {
await resend.emails.send({
from,
to: user.email,
subject: "Your OTP",
html: `Your OTP is ${otp}`,
});
},
},
}),
organizationPlugin,
twoFactorPlugin,
passkey(),
bearer(),
admin(),
multiSession(),
username(),
expo(),
],
trustedOrigins: ["better-auth://", "exp://"],
});