ragnar
ragnar
Explore posts from servers
TTCTheo's Typesafe Cult
Created by ragnar on 3/12/2025 in #questions
Tailwindcss looks weird after @uploadthing/react/styles.css
help pls
2 replies
BABetter Auth
Created by ragnar on 3/5/2025 in #help
Session duplication bug when two-factor plugin enabled
I'm really tired of looking for a solution to this problem. another source code I looked at on the internet has the same problem. I don't think the problem is caused by my code.
9 replies
BABetter Auth
Created by ragnar on 3/5/2025 in #help
Session duplication bug when two-factor plugin enabled
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { db } from "./db";
import { nextCookies } from "better-auth/next-js";
import { sendEmail } from "@/actions/send-email";
import { twoFactor } from "better-auth/plugins";

export const auth = betterAuth({
appName: "Better Auth",
database: prismaAdapter(db, {
provider: "postgresql",
}),
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
sendResetPassword: async ({ user, url, token }) => {
const newToken = `reset-password:${token}`;

if (!user.emailVerified) {
const existingToken = await db.verification.findFirst({
where: {
identifier: newToken,
},
});

await db.verification.delete({
where: {
id: existingToken?.id,
},
});

throw new Error();
}

await sendEmail({
email: user.email,
subject: "Reset your password",
text: `Click the link to reset your password: ${url}`,
});
},
},
emailVerification: {
sendOnSignUp: true,
autoSignInAfterVerification: true,
sendVerificationEmail: async ({ user, url }) => {
await sendEmail({
email: user.email,
subject: "Verify your email address",
text: `Click the link to verify your email: ${url}`,
});
},
},
user: {
deleteUser: {
enabled: true,
},
},
socialProviders: {
github: {
clientId: process.env.GITHUB_CLIENT_ID!,
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
},
},
plugins: [
twoFactor({
otpOptions: {
async sendOTP({ user, otp }) {
await sendEmail({
email: user.email,
subject: "2FA",
text: `Your OTP is ${otp}`,
});
},
},
skipVerificationOnEnable: true,
}),
nextCookies(),
],
});
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { db } from "./db";
import { nextCookies } from "better-auth/next-js";
import { sendEmail } from "@/actions/send-email";
import { twoFactor } from "better-auth/plugins";

export const auth = betterAuth({
appName: "Better Auth",
database: prismaAdapter(db, {
provider: "postgresql",
}),
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
sendResetPassword: async ({ user, url, token }) => {
const newToken = `reset-password:${token}`;

if (!user.emailVerified) {
const existingToken = await db.verification.findFirst({
where: {
identifier: newToken,
},
});

await db.verification.delete({
where: {
id: existingToken?.id,
},
});

throw new Error();
}

await sendEmail({
email: user.email,
subject: "Reset your password",
text: `Click the link to reset your password: ${url}`,
});
},
},
emailVerification: {
sendOnSignUp: true,
autoSignInAfterVerification: true,
sendVerificationEmail: async ({ user, url }) => {
await sendEmail({
email: user.email,
subject: "Verify your email address",
text: `Click the link to verify your email: ${url}`,
});
},
},
user: {
deleteUser: {
enabled: true,
},
},
socialProviders: {
github: {
clientId: process.env.GITHUB_CLIENT_ID!,
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
},
},
plugins: [
twoFactor({
otpOptions: {
async sendOTP({ user, otp }) {
await sendEmail({
email: user.email,
subject: "2FA",
text: `Your OTP is ${otp}`,
});
},
},
skipVerificationOnEnable: true,
}),
nextCookies(),
],
});
9 replies
BABetter Auth
Created by ragnar on 3/5/2025 in #help
Session duplication bug when two-factor plugin enabled
"better-auth": "^1.2.3"
9 replies
BABetter Auth
Created by ragnar on 3/5/2025 in #help
Session duplication bug when two-factor plugin enabled
any help please 😦
9 replies
BABetter Auth
Created by ragnar on 3/5/2025 in #help
Session duplication bug when two-factor plugin enabled
otp-modal -->
import { twoFactor } from "@/lib/auth-client";

const onSubmit = async (values: z.infer<typeof formSchema>) => {
const validatedData = formSchema.parse(values);

try {
await twoFactor.verifyOtp(
{
code: validatedData.code,
trustDevice: validatedData.trustDevice,
},
{
onSuccess() {
onClose();
router.push("/dashboard");
},
onError(ctx) {
setIsInvalidCode(true);
throw new Error(ctx.error.message);
},
}
);
} catch (error) {
toast.error((error as Error).message);
}
};
import { twoFactor } from "@/lib/auth-client";

const onSubmit = async (values: z.infer<typeof formSchema>) => {
const validatedData = formSchema.parse(values);

try {
await twoFactor.verifyOtp(
{
code: validatedData.code,
trustDevice: validatedData.trustDevice,
},
{
onSuccess() {
onClose();
router.push("/dashboard");
},
onError(ctx) {
setIsInvalidCode(true);
throw new Error(ctx.error.message);
},
}
);
} catch (error) {
toast.error((error as Error).message);
}
};
9 replies