Kazz
Kazz
Explore posts from servers
BABetter Auth
Created by Kazz on 2/22/2025 in #bug-reports
Organization Plugin: Empty invitation handling
After implementing organization invitation in my project, I discovered that I can send an empty email in the organization.inviteMember And the function would work correctly. Example of the bug: - User sends an invitation to the organization for an empty string email "" - The function takes it normally without throwing an error and stores it in database with email = "" Expected behavior: - User tries sending invitation to an empty email string - Error return saying that the email must be valid or something like this I know that I need to add validation for the email before giving it to the function, but I still think the validation should be implemented in this. I don't know if other functions that accept emails do the same thing as well. Might be something to look into.
2 replies
TTCTheo's Typesafe Cult
Created by Kazz on 2/21/2025 in #questions
UploadThing file accept type restriction
I'm trying to find how I can allow the <UploadButton /> to only accept images for example with extensions of (.png, .jpg ...etc). Because currently my users are able to upload .gif for example and I don't want to allow that. I searched the docs but there is nothing regarding image type restriction or acceptation. Unless I missed something...
5 replies
BABetter Auth
Created by Kazz on 2/3/2025 in #help
Organization haPermission and checkRolePermissions help
Shouldn't auth.api.hasPermission body include organizationId / organizationSlug? This is so that if we don't want to use the activeOrganiztionId since hasPermission only defaults to that. Why am I not using activeOrganizationId? I'm using the organization slug in the URL instead and checking if it exists, found it better than making the user wait around 500ms more to set the new active organization
3 replies
BABetter Auth
Created by Kazz on 12/27/2024 in #help
Secure cookies not working in production
I'm using Nextjs 15 with React 19 and latest version of better-auth 1.1.4 My production is not using the secure better auth cookies and when i add the useSecureCookies: true in my auth config no cookies get stored and I'm not able to login. I'm using the Organization plugin, Magic Link plugin, nextCookies plugin, as well as session cookie cache enabled
POST /api/auth/sign-in/social?currentURL=http%3A%2F%2Flocalhost%3A3000%2F 200 in 184ms

GET /api/auth/callback/google?state=9NIV84IUrwYVuruWPEYWko_nwuqns93S&code=4%2F0AanRRrsTA_NhXjXVO5FJxZY8thG_rQjTJy1HSNNEJpTy8q6NMt3bWCxon2lGCtC8kIqZlQ&scope=email+profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&authuser=0&prompt=none 302 in 1384ms

GET /api/auth/get-session 200 in 94ms

GET / 200 in 134ms
POST /api/auth/sign-in/social?currentURL=http%3A%2F%2Flocalhost%3A3000%2F 200 in 184ms

GET /api/auth/callback/google?state=9NIV84IUrwYVuruWPEYWko_nwuqns93S&code=4%2F0AanRRrsTA_NhXjXVO5FJxZY8thG_rQjTJy1HSNNEJpTy8q6NMt3bWCxon2lGCtC8kIqZlQ&scope=email+profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&authuser=0&prompt=none 302 in 1384ms

GET /api/auth/get-session 200 in 94ms

GET / 200 in 134ms
2 replies
BABetter Auth
Created by Kazz on 12/23/2024 in #bug-reports
Session Cache disappearing in Next.js
Expected behavior: Cached session refreshes in cookies every 30 seconds Current behavior: Cached session disappears after 30 seconds and never gets refreshed, leaving better-auth to default back to bringing the session from the database. Better-Auth version v1.1.3 (Latest) Bug Details: I started testing out session cache in my project, set the cache to 30 seconds and tried using it. After logging in, the cached session better-auth.session_data stays in my cookies for 30 seconds and then disappears, never to return. Better-auth then defaults back to bringing the session from the database. The only way I found to get the cached session back is to update the user, but then same loop happens, wait 30 seconds, disappear without being. This is some of my auth options for reference. I'm also using the Oragnization plugin
export const auth = betterAuth({
database: drizzleAdapter(db, { provider: 'pg' }),
session: { cookieCache: { enabled: true, maxAge: 30 } },
databaseHooks: {
session: {
create: {
before: async session => {
const { data, error: _error } = await getUserOrganizationAuth(session.userId)
return { data: { ...session, activeOrganizationId: data?.id } }
},
},
},
},
})
export const auth = betterAuth({
database: drizzleAdapter(db, { provider: 'pg' }),
session: { cookieCache: { enabled: true, maxAge: 30 } },
databaseHooks: {
session: {
create: {
before: async session => {
const { data, error: _error } = await getUserOrganizationAuth(session.userId)
return { data: { ...session, activeOrganizationId: data?.id } }
},
},
},
},
})
27 replies
BABetter Auth
Created by Kazz on 12/9/2024 in #help
Build error after migrating to React 19 and Next.js 15
Getting this error after migrating to react 19 and nextjs 15.
Failed to compile.

./node_modules/.pnpm/better-auth@1.0.14/node_modules/better-auth/dist/react.js
Attempted import error: 'useRef' is not exported from 'react' (imported as 'te').

Import trace for requested module:
./node_modules/.pnpm/better-auth@1.0.14/node_modules/better-auth/dist/react.js
./lib/auth-client.ts
./lib/auth-functions.ts

./node_modules/.pnpm/better-auth@1.0.14/node_modules/better-auth/dist/react.js
Attempted import error: 'useSyncExternalStore' is not exported from 'react' (imported as 'ne').

Import trace for requested module:
./node_modules/.pnpm/better-auth@1.0.14/node_modules/better-auth/dist/react.js
./lib/auth-client.ts
./lib/auth-functions.ts


> Build failed because of webpack errors
 ELIFECYCLE  Command failed with exit code 1.
Failed to compile.

./node_modules/.pnpm/better-auth@1.0.14/node_modules/better-auth/dist/react.js
Attempted import error: 'useRef' is not exported from 'react' (imported as 'te').

Import trace for requested module:
./node_modules/.pnpm/better-auth@1.0.14/node_modules/better-auth/dist/react.js
./lib/auth-client.ts
./lib/auth-functions.ts

./node_modules/.pnpm/better-auth@1.0.14/node_modules/better-auth/dist/react.js
Attempted import error: 'useSyncExternalStore' is not exported from 'react' (imported as 'ne').

Import trace for requested module:
./node_modules/.pnpm/better-auth@1.0.14/node_modules/better-auth/dist/react.js
./lib/auth-client.ts
./lib/auth-functions.ts


> Build failed because of webpack errors
 ELIFECYCLE  Command failed with exit code 1.
As well as an error making me download the oslo package
⚠ ./node_modules/.pnpm/[email protected]/node_modules/better-auth/dist
Package oslo can't be external
The request oslo/crypto matches serverExternalPackages (or the default list).
The request could not be resolved by Node.js from the project directory.
Packages that should be external need to be installed in the project directory, so they can be resolved from the output files.
Try to install it into the project directory by running npm install oslo from the project directory.
⚠ ./node_modules/.pnpm/[email protected]/node_modules/better-auth/dist
Package oslo can't be external
The request oslo/crypto matches serverExternalPackages (or the default list).
The request could not be resolved by Node.js from the project directory.
Packages that should be external need to be installed in the project directory, so they can be resolved from the output files.
Try to install it into the project directory by running npm install oslo from the project directory.
Here are the dependencies I updated:
"dependencies": {
"better-auth": "1.0.14",
"drizzle-orm": "^0.37.0",
"next": "15.0.4",
"react": "^19",
"react-dom": "^19",
},
"devDependencies": {
"@types/node": "^22",
"@types/react": "^19",
"@types/react-dom": "^19",
"drizzle-kit": "^0.29.1",
"eslint": "^9",
"eslint-config-next": "15.0.4",
"typescript": "^5"
}
"dependencies": {
"better-auth": "1.0.14",
"drizzle-orm": "^0.37.0",
"next": "15.0.4",
"react": "^19",
"react-dom": "^19",
},
"devDependencies": {
"@types/node": "^22",
"@types/react": "^19",
"@types/react-dom": "^19",
"drizzle-kit": "^0.29.1",
"eslint": "^9",
"eslint-config-next": "15.0.4",
"typescript": "^5"
}
9 replies
BABetter Auth
Created by Kazz on 12/2/2024 in #bug-reports
Updating organization metadata
Currently, after updating organization metadata, the metadata gets stringified twice, causing the data to be stored as '[object object]' This should solve the problem theoretically by checking if the metadata already a string or not and stringifiying it based on that. I didn't have time to create a PR and clone the project so i just drafted this quickly from what I saw in the file File path: packages/better-auth/src/plugins/organization/adapter.ts Untested Code:
updateOrganization: async (
organizationId: string,
data: Partial<Organization>,
) => {
let organizationUpdate = { ...data };
if (data.metadata) {
organizationUpdate.metadata = typeof data.metadata === 'string'
? data.metadata
: JSON.stringify(data.metadata);
}

const organization = await adapter.update<Organization>({
model: "organization",
where: [
{
field: "id",
value: organizationId,
},
],
update: organizationUpdate,
});
if (!organization) {
return null;
}
return {
...organization,
metadata: organization.metadata
? JSON.parse(organization.metadata)
: undefined,
};
},
updateOrganization: async (
organizationId: string,
data: Partial<Organization>,
) => {
let organizationUpdate = { ...data };
if (data.metadata) {
organizationUpdate.metadata = typeof data.metadata === 'string'
? data.metadata
: JSON.stringify(data.metadata);
}

const organization = await adapter.update<Organization>({
model: "organization",
where: [
{
field: "id",
value: organizationId,
},
],
update: organizationUpdate,
});
if (!organization) {
return null;
}
return {
...organization,
metadata: organization.metadata
? JSON.parse(organization.metadata)
: undefined,
};
},
6 replies
BABetter Auth
Created by Kazz on 11/30/2024 in #bug-reports
Typescript additional fields date type error
Jumping straight to example: Add additional fields in the db schema and in the auth config user: { additionalFields: { birthday: { type: 'string', default: null }, dob: { type: 'date', default: null }, }, }, Expected behavior await updateUser({ birthday: values.birthday?.toISOString(), dob: values.birthday && values.birthday, }) Error I'm getting: Type 'Date | undefined' is not assignable to type 'undefined'. (dob field) It is reading date types as undefined in better-auth This error only occurs with type date, any other type in better-auth config is read correctly
3 replies