mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-25 08:31:37 -05:00
feat: Allow passing id in DB hook create (#3048)
* feat(database-hooks): Allow passing `id` in DB hook `create` It's the same to using a custom `idGenerator`, except configurable by the database hook which would in theory provide more data. A use-case is to generate the id based on user info in the user before DB hook. Solves https://discord.com/channels/1288403910284935179/1379190465588367540/1384217435535835216 * chore: lint * fix: tests failing
This commit is contained in:
@@ -318,7 +318,10 @@ export const createAdapter =
|
||||
!config.disableIdGeneration &&
|
||||
!options.advanced?.database?.useNumberId
|
||||
) {
|
||||
fields.id = idField({ customModelName: unsafe_model, forceAllowId });
|
||||
fields.id = idField({
|
||||
customModelName: unsafe_model,
|
||||
forceAllowId: forceAllowId && "id" in data,
|
||||
});
|
||||
}
|
||||
for (const field in fields) {
|
||||
const value = data[field];
|
||||
|
||||
@@ -4,7 +4,6 @@ import { APIError } from "better-call";
|
||||
import { getSessionFromCtx } from "./session";
|
||||
import { setSessionCookie } from "../../cookies";
|
||||
import type { GenericEndpointContext, User } from "../../types";
|
||||
import { BASE_ERROR_CODES } from "../../error/codes";
|
||||
import { jwtVerify, type JWTPayload, type JWTVerifyResult } from "jose";
|
||||
import { signJWT } from "../../crypto/jwt";
|
||||
import { originCheck } from "../middlewares";
|
||||
|
||||
@@ -53,6 +53,7 @@ export function getWithHooks(
|
||||
? await adapter.create<T>({
|
||||
model,
|
||||
data: actualData as any,
|
||||
forceAllowId: true,
|
||||
})
|
||||
: customCreated;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user