deleteUser response: FAILED_TO_GET_USER_INFO
Hi, I'm using deleteUser() with sendDeleteAccountVerification.
E-mail is sent with correct token. But whatever I try, the response from my Express API is FAILED_TO_GET_USER_INFO.
I'm on version 1.2.7 in both client and server
Does anyone have a clue of why this response is returned?
4 Replies
Can I see your auth config?
Hi @Ping , thanks for your response. Excuse me for my late response, I was out for a few days.
This is my client config:
baseURL: import.meta.env.VITE_API_BASE_URL,
fetchOptions: {
credentials: "include",
auth: {
type: "Bearer",
token: await getToken(),
},
}
This is my Express API config:
authInstance = betterAuth({
plugins: [bearer()],
database: mongodbAdapter(nativeDb),
trustedOrigins: ["http://localhost:3000", "http://localhost:3001"],
emailAndPassword: {
enabled: true,
sendResetPassword: async ({ user, url }) => {
var message = {
from: "removed actual email address, but it's being sent/received",
to: user.email,
subject: "test",
text: "Hi " + user.name + ",\n\n Follow the link below to reset your password: \n" + url.toString(),
html:
transporter.sendMail(message, (err) => { if (err) { console.log("Error occurred. " + err.message); return process.exit(1); } }) }, }, } }); @Ping can I politely ask you to have another look?
<p>Hi ${user.name}</p><p>Follow the link below to reset your password:<br /><a href="${url.toString()}">Reset password</a></p>
,
};
transporter.sendMail(message, (err) => {
if (err) {
console.log("Error occurred. " + err.message);
return process.exit(1);
}
})
},
},
user: {
deleteUser: {
enabled: true,
sendDeleteAccountVerification: async (
{
user, // The user object
url, // The auto-generated URL for deletion
},
request // The original request object (optional)
) => {
var message = {
from: "removed actual email address, but it's being sent/received",
to: user.email,
subject: "delete user",
text: "Hi " + user.name + ",\n\n Follow the link below to remove your account: \n" + url.toString(),
};
transporter.sendMail(message, (err) => { if (err) { console.log("Error occurred. " + err.message); return process.exit(1); } }) }, }, } }); @Ping can I politely ask you to have another look?
That error occurs when there isn't an active session
Are you using auth.api.deleteUser? or using the authClient?
I'm using the authClient, I will look into the active session and let you know
From my given context it was not clear that I am usin Ionic (mobile app) with Better Auth. This prevents me from direct deleting the user in a browser window. The user never has a valid token there because it is in the app. My solution is to directly delete the account from the app (after explicit validation by the user). The other option was to let the user pass in a password on a webpage using the token. Could work, but seems to me that it will be confusing for the user.