mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-26 17:06:41 -05:00
refactor: use consistent id length (#133)
This commit is contained in:
@@ -77,14 +77,11 @@ export const signUpEmail = <O extends BetterAuthOptions>() =>
|
||||
additionalFields as any,
|
||||
);
|
||||
const createdUser = await ctx.context.internalAdapter.createUser({
|
||||
id: generateRandomString(32, alphabet("a-z", "0-9", "A-Z")),
|
||||
email: email.toLowerCase(),
|
||||
name,
|
||||
image,
|
||||
emailVerified: false,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
...additionalData,
|
||||
emailVerified: false,
|
||||
});
|
||||
if (!createdUser) {
|
||||
throw new APIError("BAD_REQUEST", {
|
||||
|
||||
@@ -157,7 +157,6 @@ export const setPassword = createAuthEndpoint(
|
||||
const passwordHash = await ctx.context.password.hash(newPassword);
|
||||
if (!account) {
|
||||
await ctx.context.internalAdapter.linkAccount({
|
||||
id: generateRandomString(32, alphabet("a-z", "0-9", "A-Z")),
|
||||
userId: session.user.id,
|
||||
providerId: "credential",
|
||||
accountId: session.user.id,
|
||||
|
||||
@@ -40,7 +40,6 @@ export const createInternalAdapter = (
|
||||
const createdUser = await createWithHooks(
|
||||
{
|
||||
id: generateId(),
|
||||
emailVerified: false,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
...user,
|
||||
@@ -218,8 +217,14 @@ export const createInternalAdapter = (
|
||||
});
|
||||
return user;
|
||||
},
|
||||
linkAccount: async (account: Account) => {
|
||||
const _account = await createWithHooks(account, "account");
|
||||
linkAccount: async (account: Omit<Account, "id"> & Record<string, any>) => {
|
||||
const _account = await createWithHooks(
|
||||
{
|
||||
...account,
|
||||
id: generateId(),
|
||||
},
|
||||
"account",
|
||||
);
|
||||
return _account;
|
||||
},
|
||||
updateUser: async (userId: string, data: Partial<User>) => {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { createAuthEndpoint, sessionMiddleware } from "../../api";
|
||||
import { alphabet, generateRandomString } from "../../crypto/random";
|
||||
import type { BetterAuthPlugin } from "../../types";
|
||||
import { setSessionCookie } from "../../utils/cookies";
|
||||
import { z } from "zod";
|
||||
@@ -95,7 +94,6 @@ export const anonymous = (options?: AnonymousOptions) => {
|
||||
const hash = await ctx.context.password.hash(password);
|
||||
const updateUserAccount =
|
||||
await ctx.context.internalAdapter.linkAccount({
|
||||
id: generateRandomString(32, alphabet("a-z", "0-9", "A-Z")),
|
||||
userId: updatedUser.id,
|
||||
providerId: "credential",
|
||||
password: hash,
|
||||
|
||||
@@ -19,6 +19,7 @@ import { getSessionFromCtx } from "../../api/routes";
|
||||
import type { BetterAuthPlugin } from "../../types/plugins";
|
||||
import { setSessionCookie } from "../../utils/cookies";
|
||||
import { BetterAuthError } from "../../error/better-auth-error";
|
||||
import { generateId } from "../../utils/id";
|
||||
|
||||
interface WebAuthnChallengeValue {
|
||||
expectedChallenge: string;
|
||||
@@ -143,7 +144,7 @@ export const passkey = (options?: PasskeyOptions) => {
|
||||
},
|
||||
});
|
||||
|
||||
const id = generateRandomString(32, alphabet("a-z", "0-9"));
|
||||
const id = generateId();
|
||||
await ctx.setSignedCookie(
|
||||
opts.advanced.webAuthnChallengeCookie,
|
||||
id,
|
||||
@@ -216,7 +217,7 @@ export const passkey = (options?: PasskeyOptions) => {
|
||||
id: session?.user.id || "",
|
||||
},
|
||||
};
|
||||
const id = generateRandomString(32, alphabet("a-z", "0-9"));
|
||||
const id = generateId();
|
||||
await ctx.setSignedCookie(
|
||||
opts.advanced.webAuthnChallengeCookie,
|
||||
id,
|
||||
@@ -306,7 +307,7 @@ export const passkey = (options?: PasskeyOptions) => {
|
||||
credentialBackedUp,
|
||||
} = registrationInfo;
|
||||
const pubKey = Buffer.from(credentialPublicKey).toString("base64");
|
||||
const userID = generateRandomString(32, alphabet("a-z", "0-9"));
|
||||
const userID = generateId();
|
||||
const newPasskey: Passkey = {
|
||||
name: ctx.body.name,
|
||||
userId: userData.id,
|
||||
|
||||
Reference in New Issue
Block a user