mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-06 04:19:20 +00:00
chore: fix type exports and sync dep versions to improve build times (#1528)
This commit is contained in:
@@ -50,7 +50,7 @@
|
||||
"@tanstack/react-query": "^5.62.3",
|
||||
"@types/better-sqlite3": "^7.6.12",
|
||||
"better-auth": "workspace:*",
|
||||
"better-call": "1.0.0-beta.5",
|
||||
"better-call": "catalog:",
|
||||
"better-sqlite3": "^11.6.0",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
|
||||
@@ -9,14 +9,13 @@
|
||||
"@types/bun": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
"typescript": "^5.7.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@noble/ciphers": "^0.6.0",
|
||||
"@types/better-sqlite3": "^7.6.12",
|
||||
"better-auth": "workspace:*",
|
||||
"better-sqlite3": "^11.6.0",
|
||||
"oslo": "^1.2.1",
|
||||
"pg": "^8.13.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -327,7 +327,7 @@ export const socialProviders = {
|
||||
),
|
||||
stringIcon: `<svg xmlns="http://www.w3.org/2000/svg" width="1.2em" height="1.2em" viewBox="0 0 448 512"><path fill="currentColor" d="M64 32C28.7 32 0 60.7 0 96v320c0 35.3 28.7 64 64 64h320c35.3 0 64-28.7 64-64V96c0-35.3-28.7-64-64-64zm297.1 84L257.3 234.6L379.4 396h-95.6L209 298.1L123.3 396H75.8l111-126.9L69.7 116h98l67.7 89.5l78.2-89.5zm-37.8 251.6L153.4 142.9h-28.3l171.8 224.7h26.3z"></path></svg>`,
|
||||
},
|
||||
roblox: {
|
||||
roblox: {
|
||||
Icon: (props?: SVGProps<any>) => (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
"@tsparticles/slim": "^3.7.1",
|
||||
"@types/better-sqlite3": "^7.6.12",
|
||||
"@vercel/og": "^0.6.4",
|
||||
"better-auth": "^0.8.8",
|
||||
"better-auth": "workspace:*",
|
||||
"better-sqlite3": "^11.6.0",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
"@radix-ui/react-label": "^2.1.1",
|
||||
"@radix-ui/react-separator": "^1.1.1",
|
||||
"@radix-ui/react-slot": "^1.1.1",
|
||||
"better-auth": "^1.1.8",
|
||||
"better-auth": "workspace:*",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"lucide-react": "^0.469.0",
|
||||
@@ -35,7 +35,7 @@
|
||||
"@types/react-dom": "18.2.18",
|
||||
"postcss": "8.4.33",
|
||||
"prettier": "3.2.4",
|
||||
"typescript": "5.3.3"
|
||||
"typescript": "^5.7.2"
|
||||
},
|
||||
"manifest": {
|
||||
"host_permissions": [
|
||||
|
||||
@@ -59,6 +59,6 @@
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/react": "^18.3.14",
|
||||
"@types/react-test-renderer": "^18.3.1",
|
||||
"typescript": "~5.3.3"
|
||||
"typescript": "^5.7.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,5 @@ import { createAuthClient } from "better-auth/react";
|
||||
export const { useSession, signIn, signOut, signUp, twoFactor } =
|
||||
createAuthClient({
|
||||
baseURL: "http://localhost:3000",
|
||||
plugins: [
|
||||
twoFactorClient({
|
||||
twoFactorPage: "/auth/two-factor",
|
||||
}),
|
||||
],
|
||||
plugins: [twoFactorClient()],
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
"vite-tsconfig-paths": "^5.1.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.6.3"
|
||||
"typescript": "^5.7.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@radix-ui/react-avatar": "^1.1.1",
|
||||
@@ -33,7 +33,7 @@
|
||||
"@tanstack/start": "^1.86.1",
|
||||
"@types/ua-parser-js": "^0.7.39",
|
||||
"@vitejs/plugin-react": "^4.3.4",
|
||||
"better-auth": "^0.6.2",
|
||||
"better-auth": "workspace:*",
|
||||
"better-sqlite3": "^11.6.0",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
@@ -48,4 +48,4 @@
|
||||
"ua-parser-js": "^0.7.39",
|
||||
"vinxi": "^0.4.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@
|
||||
"taze": "^0.18.0",
|
||||
"tinyglobby": "^0.2.10",
|
||||
"turbo": "^2.3.3",
|
||||
"typescript": "5.6.1-rc"
|
||||
"typescript": "^5.7.2"
|
||||
},
|
||||
"pnpm": {
|
||||
"overrides": {
|
||||
|
||||
@@ -589,7 +589,7 @@
|
||||
"tarn": "^3.0.2",
|
||||
"tedious": "^18.6.1",
|
||||
"tsup": "^8.3.5",
|
||||
"typescript": "5.6.1-rc",
|
||||
"typescript": "^5.7.2",
|
||||
"vitest": "^1.6.0",
|
||||
"vue": "^3.5.13"
|
||||
},
|
||||
|
||||
@@ -247,7 +247,8 @@ export const verifyEmail = createAuthEndpoint(
|
||||
{
|
||||
email: parsed.updateTo,
|
||||
emailVerified: false,
|
||||
},ctx
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
|
||||
const newToken = await createEmailVerificationToken(
|
||||
@@ -290,9 +291,13 @@ export const verifyEmail = createAuthEndpoint(
|
||||
},
|
||||
});
|
||||
}
|
||||
await ctx.context.internalAdapter.updateUserByEmail(parsed.email, {
|
||||
emailVerified: true,
|
||||
},ctx);
|
||||
await ctx.context.internalAdapter.updateUserByEmail(
|
||||
parsed.email,
|
||||
{
|
||||
emailVerified: true,
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
if (ctx.context.options.emailVerification?.autoSignInAfterVerification) {
|
||||
const currentSession = await getSessionFromCtx(ctx);
|
||||
if (!currentSession || currentSession.user.email !== parsed.email) {
|
||||
|
||||
@@ -263,17 +263,24 @@ export const resetPassword = createAuthEndpoint(
|
||||
const accounts = await ctx.context.internalAdapter.findAccounts(userId);
|
||||
const account = accounts.find((ac) => ac.providerId === "credential");
|
||||
if (!account) {
|
||||
await ctx.context.internalAdapter.createAccount({
|
||||
userId,
|
||||
providerId: "credential",
|
||||
password: hashedPassword,
|
||||
accountId: userId,
|
||||
}, ctx);
|
||||
await ctx.context.internalAdapter.createAccount(
|
||||
{
|
||||
userId,
|
||||
providerId: "credential",
|
||||
password: hashedPassword,
|
||||
accountId: userId,
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
return ctx.json({
|
||||
status: true,
|
||||
});
|
||||
}
|
||||
await ctx.context.internalAdapter.updatePassword(userId, hashedPassword, ctx);
|
||||
await ctx.context.internalAdapter.updatePassword(
|
||||
userId,
|
||||
hashedPassword,
|
||||
ctx,
|
||||
);
|
||||
return ctx.json({
|
||||
status: true,
|
||||
});
|
||||
|
||||
@@ -12,10 +12,10 @@ import type {
|
||||
GenericEndpointContext,
|
||||
InferSession,
|
||||
InferUser,
|
||||
Prettify,
|
||||
Session,
|
||||
User,
|
||||
} from "../../types";
|
||||
import type { Prettify } from "../../types/helper";
|
||||
import { safeJSONParse } from "../../utils/json";
|
||||
import { BASE_ERROR_CODES } from "../../error/codes";
|
||||
import { createHMAC } from "@better-auth/utils/hmac";
|
||||
|
||||
@@ -145,13 +145,16 @@ export const signUpEmail = <O extends BetterAuthOptions>() =>
|
||||
);
|
||||
let createdUser: User;
|
||||
try {
|
||||
createdUser = await ctx.context.internalAdapter.createUser({
|
||||
email: email.toLowerCase(),
|
||||
name,
|
||||
image,
|
||||
...additionalData,
|
||||
emailVerified: false,
|
||||
}, ctx);
|
||||
createdUser = await ctx.context.internalAdapter.createUser(
|
||||
{
|
||||
email: email.toLowerCase(),
|
||||
name,
|
||||
image,
|
||||
...additionalData,
|
||||
emailVerified: false,
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
if (!createdUser) {
|
||||
throw new APIError("BAD_REQUEST", {
|
||||
message: BASE_ERROR_CODES.FAILED_TO_CREATE_USER,
|
||||
@@ -175,12 +178,15 @@ export const signUpEmail = <O extends BetterAuthOptions>() =>
|
||||
* Link the account to the user
|
||||
*/
|
||||
const hash = await ctx.context.password.hash(password);
|
||||
await ctx.context.internalAdapter.linkAccount({
|
||||
userId: createdUser.id,
|
||||
providerId: "credential",
|
||||
accountId: createdUser.id,
|
||||
password: hash,
|
||||
}, ctx);
|
||||
await ctx.context.internalAdapter.linkAccount(
|
||||
{
|
||||
userId: createdUser.id,
|
||||
providerId: "credential",
|
||||
accountId: createdUser.id,
|
||||
password: hash,
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
if (
|
||||
ctx.context.options.emailVerification?.sendOnSignUp ||
|
||||
ctx.context.options.emailAndPassword.requireEmailVerification
|
||||
|
||||
@@ -100,7 +100,8 @@ export const updateUser = <O extends BetterAuthOptions>() =>
|
||||
name,
|
||||
image,
|
||||
...additionalFields,
|
||||
},ctx
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
/**
|
||||
* Update the session cookie with the new user data
|
||||
@@ -289,12 +290,15 @@ export const setPassword = createAuthEndpoint(
|
||||
);
|
||||
const passwordHash = await ctx.context.password.hash(newPassword);
|
||||
if (!account) {
|
||||
await ctx.context.internalAdapter.linkAccount({
|
||||
userId: session.user.id,
|
||||
providerId: "credential",
|
||||
accountId: session.user.id,
|
||||
password: passwordHash,
|
||||
}, ctx);
|
||||
await ctx.context.internalAdapter.linkAccount(
|
||||
{
|
||||
userId: session.user.id,
|
||||
providerId: "credential",
|
||||
accountId: session.user.id,
|
||||
password: passwordHash,
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
return ctx.json({
|
||||
status: true,
|
||||
});
|
||||
@@ -582,7 +586,8 @@ export const changeEmail = createAuthEndpoint(
|
||||
ctx.context.session.user.email,
|
||||
{
|
||||
email: ctx.body.newEmail,
|
||||
},ctx
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
return ctx.json({
|
||||
status: true,
|
||||
|
||||
@@ -6,10 +6,9 @@ import type {
|
||||
InferPluginTypes,
|
||||
InferSession,
|
||||
InferUser,
|
||||
PrettifyDeep,
|
||||
Expand,
|
||||
AuthContext,
|
||||
} from "./types";
|
||||
import type { PrettifyDeep, Expand } from "./types/helper";
|
||||
import { getBaseURL } from "./utils/url";
|
||||
import type { FilterActions, InferAPI } from "./types";
|
||||
import { BASE_ERROR_CODES } from "./error/codes";
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getTestInstance } from "../test-utils/test-instance";
|
||||
import { getCookies, type BetterAuthOptions } from "../index";
|
||||
import { getCookies } from "../cookies";
|
||||
import type { BetterAuthOptions } from "../types/options";
|
||||
|
||||
describe("cookies", async () => {
|
||||
const { client, testUser } = await getTestInstance();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { ZodSchema } from "zod";
|
||||
import type { BetterAuthOptions, LiteralString } from "../types";
|
||||
import type { BetterAuthOptions } from "../types";
|
||||
import type { LiteralString } from "../types/helper";
|
||||
|
||||
export type FieldType =
|
||||
| "string"
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
export * from "./auth";
|
||||
export * from "./types";
|
||||
export * from "./error";
|
||||
export * from "./cookies";
|
||||
export * from "./utils";
|
||||
//@ts-expect-error
|
||||
export type * from "better-call";
|
||||
export type * from "zod";
|
||||
|
||||
@@ -7,7 +7,6 @@ import type {
|
||||
Adapter,
|
||||
BetterAuthOptions,
|
||||
BetterAuthPlugin,
|
||||
LiteralUnion,
|
||||
Models,
|
||||
SecondaryStorage,
|
||||
Session,
|
||||
@@ -26,6 +25,7 @@ import { generateId } from "./utils";
|
||||
import { env, isProduction } from "./utils/env";
|
||||
import { checkPassword } from "./utils/password";
|
||||
import { getBaseURL } from "./utils/url";
|
||||
import type { LiteralUnion } from "./types/helper";
|
||||
|
||||
export const init = async (options: BetterAuthOptions) => {
|
||||
const adapter = await getAdapter(options);
|
||||
|
||||
@@ -59,17 +59,20 @@ export async function handleOAuthUserInfo(
|
||||
};
|
||||
}
|
||||
try {
|
||||
await c.context.internalAdapter.linkAccount({
|
||||
providerId: account.providerId,
|
||||
accountId: userInfo.id.toString(),
|
||||
userId: dbUser.user.id,
|
||||
accessToken: account.accessToken,
|
||||
idToken: account.idToken,
|
||||
refreshToken: account.refreshToken,
|
||||
accessTokenExpiresAt: account.accessTokenExpiresAt,
|
||||
refreshTokenExpiresAt: account.refreshTokenExpiresAt,
|
||||
scope: account.scope,
|
||||
}, c);
|
||||
await c.context.internalAdapter.linkAccount(
|
||||
{
|
||||
providerId: account.providerId,
|
||||
accountId: userInfo.id.toString(),
|
||||
userId: dbUser.user.id,
|
||||
accessToken: account.accessToken,
|
||||
idToken: account.idToken,
|
||||
refreshToken: account.refreshToken,
|
||||
accessTokenExpiresAt: account.accessTokenExpiresAt,
|
||||
refreshTokenExpiresAt: account.refreshTokenExpiresAt,
|
||||
scope: account.scope,
|
||||
},
|
||||
c,
|
||||
);
|
||||
} catch (e) {
|
||||
logger.error("Unable to link account", e);
|
||||
return {
|
||||
@@ -93,7 +96,7 @@ export async function handleOAuthUserInfo(
|
||||
await c.context.internalAdapter.updateAccount(
|
||||
hasBeenLinked.id,
|
||||
updateData,
|
||||
c
|
||||
c,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ describe("additionalFields", async () => {
|
||||
nonRequiredFiled: "non-required-field",
|
||||
},
|
||||
})
|
||||
.catch((e) => {});
|
||||
.catch(() => {});
|
||||
|
||||
const client = createAuthClient({
|
||||
plugins: [
|
||||
|
||||
@@ -105,15 +105,18 @@ export const anonymous = (options?: AnonymousOptions) => {
|
||||
options || {};
|
||||
const id = ctx.context.generateId({ model: "user" });
|
||||
const email = `temp-${id}@${emailDomainName}`;
|
||||
const newUser = await ctx.context.internalAdapter.createUser({
|
||||
id,
|
||||
email,
|
||||
emailVerified: false,
|
||||
isAnonymous: true,
|
||||
name: "Anonymous",
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
}, ctx);
|
||||
const newUser = await ctx.context.internalAdapter.createUser(
|
||||
{
|
||||
id,
|
||||
email,
|
||||
emailVerified: false,
|
||||
isAnonymous: true,
|
||||
name: "Anonymous",
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
if (!newUser) {
|
||||
throw ctx.error("INTERNAL_SERVER_ERROR", {
|
||||
message: ERROR_CODES.FAILED_TO_CREATE_USER,
|
||||
|
||||
@@ -3,13 +3,13 @@ import type { Provider } from "./types";
|
||||
export const defaultEndpoints = ["/sign-up", "/sign-in", "/forget-password"];
|
||||
|
||||
export const Providers = {
|
||||
CLOUDFLARE_TURNSTILE: "cloudflare-turnstile",
|
||||
GOOGLE_RECAPTCHA: "google-recaptcha",
|
||||
CLOUDFLARE_TURNSTILE: "cloudflare-turnstile",
|
||||
GOOGLE_RECAPTCHA: "google-recaptcha",
|
||||
} as const;
|
||||
|
||||
export const siteVerifyMap: Record<Provider, string> = {
|
||||
[Providers.CLOUDFLARE_TURNSTILE]:
|
||||
"https://challenges.cloudflare.com/turnstile/v0/siteverify",
|
||||
[Providers.GOOGLE_RECAPTCHA]:
|
||||
"https://www.google.com/recaptcha/api/siteverify",
|
||||
[Providers.CLOUDFLARE_TURNSTILE]:
|
||||
"https://challenges.cloudflare.com/turnstile/v0/siteverify",
|
||||
[Providers.GOOGLE_RECAPTCHA]:
|
||||
"https://www.google.com/recaptcha/api/siteverify",
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export const CAPTCHA_ERROR_CODES = {
|
||||
MISSING_RESPONSE: "Missing CAPTCHA response",
|
||||
SERVICE_UNAVAILABLE: "CAPTCHA service unavailable",
|
||||
VERIFICATION_FAILED: "Captcha verification failed",
|
||||
UNKNOWN_ERROR: "Something went wrong",
|
||||
MISSING_RESPONSE: "Missing CAPTCHA response",
|
||||
SERVICE_UNAVAILABLE: "CAPTCHA service unavailable",
|
||||
VERIFICATION_FAILED: "Captcha verification failed",
|
||||
UNKNOWN_ERROR: "Something went wrong",
|
||||
} as const;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { BetterAuthPlugin } from "better-auth/plugins";
|
||||
import type { BetterAuthPlugin } from "../../plugins";
|
||||
import type { Provider } from "./types";
|
||||
import { defaultEndpoints, Providers, siteVerifyMap } from "./constants";
|
||||
import { CAPTCHA_ERROR_CODES } from "./error-codes";
|
||||
|
||||
@@ -2,30 +2,30 @@ import type { Providers } from "./constants";
|
||||
export type Provider = (typeof Providers)[keyof typeof Providers];
|
||||
|
||||
export type TurnstileSiteVerifyResponse = {
|
||||
success: boolean;
|
||||
"error-codes"?: string[];
|
||||
challenge_ts?: string;
|
||||
hostname?: string;
|
||||
action?: string;
|
||||
cdata?: string;
|
||||
metadata?: {
|
||||
interactive: boolean;
|
||||
};
|
||||
messages?: string[];
|
||||
success: boolean;
|
||||
"error-codes"?: string[];
|
||||
challenge_ts?: string;
|
||||
hostname?: string;
|
||||
action?: string;
|
||||
cdata?: string;
|
||||
metadata?: {
|
||||
interactive: boolean;
|
||||
};
|
||||
messages?: string[];
|
||||
};
|
||||
|
||||
export type GoogleReCAPTCHASiteVerifyResponse = {
|
||||
success: boolean;
|
||||
challenge_ts: string;
|
||||
hostname: string;
|
||||
"error-codes":
|
||||
| Array<
|
||||
| "missing-input-secret"
|
||||
| "invalid-input-secret"
|
||||
| "missing-input-response"
|
||||
| "invalid-input-response"
|
||||
| "bad-request"
|
||||
| "timeout-or-duplicate"
|
||||
>
|
||||
| undefined;
|
||||
success: boolean;
|
||||
challenge_ts: string;
|
||||
hostname: string;
|
||||
"error-codes":
|
||||
| Array<
|
||||
| "missing-input-secret"
|
||||
| "invalid-input-secret"
|
||||
| "missing-input-response"
|
||||
| "invalid-input-response"
|
||||
| "bad-request"
|
||||
| "timeout-or-duplicate"
|
||||
>
|
||||
| undefined;
|
||||
};
|
||||
|
||||
@@ -4,41 +4,41 @@ import { CAPTCHA_ERROR_CODES } from "../error-codes";
|
||||
import type { TurnstileSiteVerifyResponse } from "../types";
|
||||
|
||||
type Params = {
|
||||
siteVerifyURL: string;
|
||||
secretKey: string;
|
||||
captchaResponse: string;
|
||||
siteVerifyURL: string;
|
||||
secretKey: string;
|
||||
captchaResponse: string;
|
||||
};
|
||||
|
||||
export const cloudflareTurnstile = async ({
|
||||
siteVerifyURL,
|
||||
captchaResponse,
|
||||
secretKey,
|
||||
siteVerifyURL,
|
||||
captchaResponse,
|
||||
secretKey,
|
||||
}: Params) => {
|
||||
const response = await betterFetch<TurnstileSiteVerifyResponse>(
|
||||
siteVerifyURL,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
secret: secretKey,
|
||||
response: captchaResponse,
|
||||
}),
|
||||
},
|
||||
);
|
||||
const response = await betterFetch<TurnstileSiteVerifyResponse>(
|
||||
siteVerifyURL,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
secret: secretKey,
|
||||
response: captchaResponse,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.data || response.error) {
|
||||
return middlewareResponse({
|
||||
message: CAPTCHA_ERROR_CODES.SERVICE_UNAVAILABLE,
|
||||
status: 503,
|
||||
});
|
||||
}
|
||||
if (!response.data || response.error) {
|
||||
return middlewareResponse({
|
||||
message: CAPTCHA_ERROR_CODES.SERVICE_UNAVAILABLE,
|
||||
status: 503,
|
||||
});
|
||||
}
|
||||
|
||||
if (!response.data.success) {
|
||||
return middlewareResponse({
|
||||
message: CAPTCHA_ERROR_CODES.VERIFICATION_FAILED,
|
||||
status: 403,
|
||||
});
|
||||
}
|
||||
if (!response.data.success) {
|
||||
return middlewareResponse({
|
||||
message: CAPTCHA_ERROR_CODES.VERIFICATION_FAILED,
|
||||
status: 403,
|
||||
});
|
||||
}
|
||||
|
||||
return undefined;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
@@ -4,41 +4,41 @@ import { CAPTCHA_ERROR_CODES } from "../error-codes";
|
||||
import type { GoogleReCAPTCHASiteVerifyResponse } from "../types";
|
||||
|
||||
type Params = {
|
||||
siteVerifyURL: string;
|
||||
secretKey: string;
|
||||
captchaResponse: string;
|
||||
siteVerifyURL: string;
|
||||
secretKey: string;
|
||||
captchaResponse: string;
|
||||
};
|
||||
|
||||
export const googleReCAPTCHA = async ({
|
||||
siteVerifyURL,
|
||||
captchaResponse,
|
||||
secretKey,
|
||||
siteVerifyURL,
|
||||
captchaResponse,
|
||||
secretKey,
|
||||
}: Params) => {
|
||||
const response = await betterFetch<GoogleReCAPTCHASiteVerifyResponse>(
|
||||
siteVerifyURL,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
secret: secretKey,
|
||||
response: captchaResponse,
|
||||
}),
|
||||
},
|
||||
);
|
||||
const response = await betterFetch<GoogleReCAPTCHASiteVerifyResponse>(
|
||||
siteVerifyURL,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
secret: secretKey,
|
||||
response: captchaResponse,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.data || response.error) {
|
||||
return middlewareResponse({
|
||||
message: CAPTCHA_ERROR_CODES.SERVICE_UNAVAILABLE,
|
||||
status: 503,
|
||||
});
|
||||
}
|
||||
if (!response.data || response.error) {
|
||||
return middlewareResponse({
|
||||
message: CAPTCHA_ERROR_CODES.SERVICE_UNAVAILABLE,
|
||||
status: 503,
|
||||
});
|
||||
}
|
||||
|
||||
if (!response.data.success) {
|
||||
return middlewareResponse({
|
||||
message: CAPTCHA_ERROR_CODES.VERIFICATION_FAILED,
|
||||
status: 403,
|
||||
});
|
||||
}
|
||||
if (!response.data.success) {
|
||||
return middlewareResponse({
|
||||
message: CAPTCHA_ERROR_CODES.VERIFICATION_FAILED,
|
||||
status: 403,
|
||||
});
|
||||
}
|
||||
|
||||
return undefined;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
@@ -115,7 +115,7 @@ export const oneTap = (options?: OneTapOptions) =>
|
||||
providerId: "google",
|
||||
accountId: sub,
|
||||
},
|
||||
ctx
|
||||
ctx,
|
||||
);
|
||||
if (!newUser) {
|
||||
throw new APIError("INTERNAL_SERVER_ERROR", {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { generator } from "./generator";
|
||||
import { logo } from "./logo";
|
||||
import type { BetterAuthPlugin, LiteralString } from "../../types";
|
||||
import type { BetterAuthPlugin } from "../../types";
|
||||
import type { LiteralString } from "../../types/helper";
|
||||
|
||||
import { APIError, createAuthEndpoint } from "../../api";
|
||||
|
||||
const getHTML = (apiReference: Record<string, any>) => `<!doctype html>
|
||||
|
||||
@@ -447,7 +447,8 @@ export const phoneNumber = (options?: PhoneNumberOptions) => {
|
||||
{
|
||||
[opts.phoneNumber]: ctx.body.phoneNumber,
|
||||
[opts.phoneNumberVerified]: true,
|
||||
},ctx
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
return ctx.json({
|
||||
status: true,
|
||||
@@ -477,18 +478,21 @@ export const phoneNumber = (options?: PhoneNumberOptions) => {
|
||||
});
|
||||
if (!user) {
|
||||
if (options?.signUpOnVerification) {
|
||||
user = await ctx.context.internalAdapter.createUser({
|
||||
email: options.signUpOnVerification.getTempEmail(
|
||||
ctx.body.phoneNumber,
|
||||
),
|
||||
name: options.signUpOnVerification.getTempName
|
||||
? options.signUpOnVerification.getTempName(
|
||||
ctx.body.phoneNumber,
|
||||
)
|
||||
: ctx.body.phoneNumber,
|
||||
[opts.phoneNumber]: ctx.body.phoneNumber,
|
||||
[opts.phoneNumberVerified]: true,
|
||||
}, ctx);
|
||||
user = await ctx.context.internalAdapter.createUser(
|
||||
{
|
||||
email: options.signUpOnVerification.getTempEmail(
|
||||
ctx.body.phoneNumber,
|
||||
),
|
||||
name: options.signUpOnVerification.getTempName
|
||||
? options.signUpOnVerification.getTempName(
|
||||
ctx.body.phoneNumber,
|
||||
)
|
||||
: ctx.body.phoneNumber,
|
||||
[opts.phoneNumber]: ctx.body.phoneNumber,
|
||||
[opts.phoneNumberVerified]: true,
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
if (!user) {
|
||||
throw new APIError("INTERNAL_SERVER_ERROR", {
|
||||
message: BASE_ERROR_CODES.FAILED_TO_CREATE_USER,
|
||||
@@ -496,9 +500,13 @@ export const phoneNumber = (options?: PhoneNumberOptions) => {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
user = await ctx.context.internalAdapter.updateUser(user.id, {
|
||||
[opts.phoneNumberVerified]: true,
|
||||
},ctx);
|
||||
user = await ctx.context.internalAdapter.updateUser(
|
||||
user.id,
|
||||
{
|
||||
[opts.phoneNumberVerified]: true,
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
|
||||
@@ -290,7 +290,7 @@ describe("provisioning", async (ctx) => {
|
||||
headers,
|
||||
});
|
||||
const member = org?.members.find(
|
||||
(m) => m.user.email === "sso-user@localhost:8000.com",
|
||||
(m: any) => m.user.email === "sso-user@localhost:8000.com",
|
||||
);
|
||||
expect(member).toMatchObject({
|
||||
role: "member",
|
||||
|
||||
@@ -103,7 +103,8 @@ export const twoFactor = (options?: TwoFactorOptions) => {
|
||||
user.id,
|
||||
{
|
||||
twoFactorEnabled: true,
|
||||
},ctx
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
const newSession = await ctx.context.internalAdapter.createSession(
|
||||
updatedUser.id,
|
||||
@@ -203,7 +204,8 @@ export const twoFactor = (options?: TwoFactorOptions) => {
|
||||
user.id,
|
||||
{
|
||||
twoFactorEnabled: false,
|
||||
},ctx
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
await ctx.context.adapter.delete({
|
||||
model: opts.twoFactorTable,
|
||||
|
||||
@@ -259,7 +259,8 @@ export const totp2fa = (options?: TOTPOptions) => {
|
||||
user.id,
|
||||
{
|
||||
twoFactorEnabled: true,
|
||||
},ctx
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
const newSession = await ctx.context.internalAdapter
|
||||
.createSession(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Prettify } from "../types";
|
||||
import type { Prettify } from "../types/helper";
|
||||
import { apple } from "./apple";
|
||||
import { discord } from "./discord";
|
||||
import { facebook } from "./facebook";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Endpoint } from "better-call";
|
||||
import type { PrettifyDeep, UnionToIntersection } from ".";
|
||||
import type { PrettifyDeep, UnionToIntersection } from "../types/helper";
|
||||
|
||||
export type FilteredAPI<API> = Omit<
|
||||
API,
|
||||
|
||||
@@ -2,7 +2,6 @@ export type * from "./options";
|
||||
export type * from "./models";
|
||||
export type * from "../init";
|
||||
export type * from "./plugins";
|
||||
export type * from "./helper";
|
||||
export type * from "./context";
|
||||
export type * from "./adapter";
|
||||
export * from "../client/types";
|
||||
|
||||
@@ -12,11 +12,12 @@ import type { AdapterInstance, SecondaryStorage } from "./adapter";
|
||||
import type { KyselyDatabaseType } from "../adapters/kysely-adapter/types";
|
||||
import type { FieldAttribute } from "../db";
|
||||
import type { Models, RateLimit } from "./models";
|
||||
import type { AuthContext, LiteralUnion, OmitId } from ".";
|
||||
import type { AuthContext } from ".";
|
||||
import type { CookieOptions } from "better-call";
|
||||
import type { Database } from "better-sqlite3";
|
||||
import type { Logger } from "../utils";
|
||||
import type { AuthMiddleware } from "../plugins";
|
||||
import type { LiteralUnion, OmitId } from "./helper";
|
||||
|
||||
export type BetterAuthOptions = {
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,11 @@ import type { Migration } from "kysely";
|
||||
import { type AuthMiddleware } from "../api/call";
|
||||
import type { FieldAttribute } from "../db/field";
|
||||
import type { HookEndpointContext } from ".";
|
||||
import type { DeepPartial, LiteralString, UnionToIntersection } from ".";
|
||||
import type {
|
||||
DeepPartial,
|
||||
LiteralString,
|
||||
UnionToIntersection,
|
||||
} from "../types/helper";
|
||||
|
||||
import type { AuthContext, BetterAuthOptions } from ".";
|
||||
import type { Endpoint } from "better-call";
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
"better-auth": "workspace:*"
|
||||
},
|
||||
"dependencies": {
|
||||
"better-call": "1.0.0-beta.4",
|
||||
"better-call": "catalog:",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"files": [
|
||||
|
||||
2276
pnpm-lock.yaml
generated
2276
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user