mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-23 23:52:05 -05:00
feat: return false from generateId callback to imply database-generated ID (#3723)
* feat: return false from generateId to imply database-generated ID * chore: add changeset * chore: update changeset --------- Co-authored-by: Bereket Engida <86073083+Bekacru@users.noreply.github.com>
This commit is contained in:
5
.changeset/funny-rules-rest.md
Normal file
5
.changeset/funny-rules-rest.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"better-auth": patch
|
||||
---
|
||||
|
||||
feat: allow returning false from `generateId` callback to imply database-generated ID
|
||||
@@ -205,7 +205,7 @@ export type AuthContext = {
|
||||
generateId: (options: {
|
||||
model: LiteralUnion<Models, string>;
|
||||
size?: number;
|
||||
}) => string;
|
||||
}) => string | false;
|
||||
secondaryStorage: SecondaryStorage | undefined;
|
||||
password: {
|
||||
hash: (password: string) => Promise<string>;
|
||||
|
||||
@@ -16,6 +16,7 @@ import { parseSetCookieHeader, setSessionCookie } from "../../cookies";
|
||||
import { getOrigin } from "../../utils/url";
|
||||
import { mergeSchema } from "../../db/schema";
|
||||
import type { EndpointContext } from "better-call";
|
||||
import { generateId } from "../../utils/id";
|
||||
|
||||
export interface UserWithAnonymous extends User {
|
||||
isAnonymous: boolean;
|
||||
@@ -119,7 +120,7 @@ export const anonymous = (options?: AnonymousOptions) => {
|
||||
async (ctx) => {
|
||||
const { emailDomainName = getOrigin(ctx.context.baseURL) } =
|
||||
options || {};
|
||||
const id = ctx.context.generateId({ model: "user" });
|
||||
const id = generateId();
|
||||
const email = `temp-${id}@${emailDomainName}`;
|
||||
const name = (await options?.generateName?.(ctx)) || "Anonymous";
|
||||
const newUser = await ctx.context.internalAdapter.createUser(
|
||||
|
||||
@@ -762,7 +762,7 @@ export type BetterAuthOptions = {
|
||||
| ((options: {
|
||||
model: LiteralUnion<Models, string>;
|
||||
size?: number;
|
||||
}) => string)
|
||||
}) => string | false)
|
||||
| false;
|
||||
};
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user