Auth failure

Hi guys i have two separate apps a nextjs and a honojs backend both using better-auth for some reason i cant make a login request it just returns the following error
{
"code": "FAILED_TO_CREATE_USER",
"message": "Failed to create user",
"details": {},
"status": 422,
"statusText": "Unprocessable Entity"
}
{
"code": "FAILED_TO_CREATE_USER",
"message": "Failed to create user",
"details": {},
"status": 422,
"statusText": "Unprocessable Entity"
}
does anyone know what the issue may be?
12 Replies
Dominik
Dominik3mo ago
There really needs to be better error messages lol
sebastian
sebastian3mo ago
share code, auth config
Dominik
Dominik3mo ago
export const authClient = createAuthClient({
baseURL: process.env.NEXT_PUBLIC_API_URL,
basePath: "/v1/auth",
plugins: [
adminClient(),
inferAdditionalFields({
user: {
imageHash: {
type: "string",
required: false,
},
},
}),
],
});
export const authClient = createAuthClient({
baseURL: process.env.NEXT_PUBLIC_API_URL,
basePath: "/v1/auth",
plugins: [
adminClient(),
inferAdditionalFields({
user: {
imageHash: {
type: "string",
required: false,
},
},
}),
],
});
backend too?
export const auth = betterAuth({
trustedOrigins,
basePath: "/v1/auth",
appName: "Local",
session: {
cookieCache: {
enabled: true,
maxAge: 60 * 60,
},
},
plugins: [
expo(),
admin(),
anonymous(),
haveIBeenPwned({
customPasswordCompromisedMessage:
"Ihr Passwort wurde in einem Datenleck gefunden. Bitte wählen Sie ein anderes.",
}),
twoFactor(),
emailOTP({
async sendVerificationOTP({ email, otp }) {
await sendVerificationEmail({
userEmail: email,
otp: otp,
});
},
}),
],
database: prismaAdapter(prisma, {
provider: "postgresql",
}),
emailAndPassword: {
enabled: true,
},
socialProviders: {
google: {
clientId: Bun.env.GOOGLE_CLIENT_ID,
clientSecret: Bun.env.GOOGLE_CLIENT_SECRET,
},
apple: {
clientId: Bun.env.APPLE_CLIENT_ID,
clientSecret: Bun.env.APPLE_CLIENT_SECRET,
//appBundleIdentifier: Bun.env.APPLE_APP_BUNDLE_IDENTIFIER!, Needed in the future when setting up apple login
},
facebook: {
clientId: Bun.env.FACEBOOK_CLIENT_ID,
clientSecret: Bun.env.FACEBOOK_CLIENT_SECRET,
},
},
user: {
additionalFields: {
isContractor: {
type: "boolean",
required: false,
defaultValue: false,
},
imageHash: {
type: "string",
required: false,
},
},
},
databaseHooks: {
user: {
create: {
before: async (user) => {
if (user.image) {
const imageHash = await encodeImageToBlurhash(user.image);
return {
data: {
...user,
imageHash,
},
};
}
// If no image, just return the user as is
return {
data: user,
};
},
},
},
},
});
export const auth = betterAuth({
trustedOrigins,
basePath: "/v1/auth",
appName: "Local",
session: {
cookieCache: {
enabled: true,
maxAge: 60 * 60,
},
},
plugins: [
expo(),
admin(),
anonymous(),
haveIBeenPwned({
customPasswordCompromisedMessage:
"Ihr Passwort wurde in einem Datenleck gefunden. Bitte wählen Sie ein anderes.",
}),
twoFactor(),
emailOTP({
async sendVerificationOTP({ email, otp }) {
await sendVerificationEmail({
userEmail: email,
otp: otp,
});
},
}),
],
database: prismaAdapter(prisma, {
provider: "postgresql",
}),
emailAndPassword: {
enabled: true,
},
socialProviders: {
google: {
clientId: Bun.env.GOOGLE_CLIENT_ID,
clientSecret: Bun.env.GOOGLE_CLIENT_SECRET,
},
apple: {
clientId: Bun.env.APPLE_CLIENT_ID,
clientSecret: Bun.env.APPLE_CLIENT_SECRET,
//appBundleIdentifier: Bun.env.APPLE_APP_BUNDLE_IDENTIFIER!, Needed in the future when setting up apple login
},
facebook: {
clientId: Bun.env.FACEBOOK_CLIENT_ID,
clientSecret: Bun.env.FACEBOOK_CLIENT_SECRET,
},
},
user: {
additionalFields: {
isContractor: {
type: "boolean",
required: false,
defaultValue: false,
},
imageHash: {
type: "string",
required: false,
},
},
},
databaseHooks: {
user: {
create: {
before: async (user) => {
if (user.image) {
const imageHash = await encodeImageToBlurhash(user.image);
return {
data: {
...user,
imageHash,
},
};
}
// If no image, just return the user as is
return {
data: user,
};
},
},
},
},
});
thats le backend
nikatune
nikatune3mo ago
whats output on encodeImageToBlurhash function ?
Dominik
Dominik3mo ago
returns a Promise<String>
nikatune
nikatune3mo ago
you answered your question send your function codes its not even related to ba but its ok
Dominik
Dominik3mo ago
how
nikatune
nikatune3mo ago
send me your encodeImageToBlurhash codes
Dominik
Dominik3mo ago
const getImageData = (image: Image): ImageData => {
const canvas = createCanvas(image.width, image.height);
const context = canvas.getContext("2d");
context.drawImage(image, 0, 0, image.width, image.height);
return context.getImageData(0, 0, image.width, image.height);
};

export const encodeImageToBlurhash = async (imageUrl: string) => {
const image = await loadImage(imageUrl);
const imageData = getImageData(image);
return encode(imageData.data, imageData.width, imageData.height, 4, 4);
};
const getImageData = (image: Image): ImageData => {
const canvas = createCanvas(image.width, image.height);
const context = canvas.getContext("2d");
context.drawImage(image, 0, 0, image.width, image.height);
return context.getImageData(0, 0, image.width, image.height);
};

export const encodeImageToBlurhash = async (imageUrl: string) => {
const image = await loadImage(imageUrl);
const imageData = getImageData(image);
return encode(imageData.data, imageData.width, imageData.height, 4, 4);
};
pretty simple ig the issue could lay in the image if the source is invalid it fails havent tested that yet probably need to handle that better
nikatune
nikatune3mo ago
its not related on better-auth you should fix your other functions
Dominik
Dominik3mo ago
Well yea ig just got confused by the error better auth was throwing But yea nothing wrong with the functions just need to handle invalid images
nikatune
nikatune3mo ago
yeah sir

Did you find this page helpful?