roque
roque
BABetter Auth
Created by roque on 4/4/2025 in #help
Middleware - Better Auth
No description
14 replies
BABetter Auth
Created by roque on 2/6/2025 in #help
Resseting password
Hi everyone, I'm trying to implement a feature where the user can change their password without email verification, just a simple form where they enter the new password. However, I’m getting the following error in the browser: Object { message: "invalid token", code: "INVALID_TOKEN", status: 400, statusText: "BAD_REQUEST" } Here’s the code I’m using to submit the new password:
async function onSubmit(dataPassword: any) {
const token = new URLSearchParams(window.location.search).get("token");
console.log("token", token);

try {
await authClient.resetPassword(
{
newPassword: "dataPassword",
},
{
onResponse: () => {},
onRequest: () => {},
onSuccess: () => {
console.log("Sucess");
},
onError: (ctx) => {
console.log(ctx.error);
},
}
);
} catch (error) {
console.log("Error in catch");
console.log(error);
}
}
async function onSubmit(dataPassword: any) {
const token = new URLSearchParams(window.location.search).get("token");
console.log("token", token);

try {
await authClient.resetPassword(
{
newPassword: "dataPassword",
},
{
onResponse: () => {},
onRequest: () => {},
onSuccess: () => {
console.log("Sucess");
},
onError: (ctx) => {
console.log(ctx.error);
},
}
);
} catch (error) {
console.log("Error in catch");
console.log(error);
}
}
And also my auth.ts:
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "sqlite",
}),
emailAndPassword: {
minPasswordLength: 3,
enabled: true,
autoSignIn: true,
},
session:{
cookieCache:{
enabled: true
}
}
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "sqlite",
}),
emailAndPassword: {
minPasswordLength: 3,
enabled: true,
autoSignIn: true,
},
session:{
cookieCache:{
enabled: true
}
}
Does anyone know why this is happening?
3 replies