mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-11 04:19:31 +00:00
chore: remove unused code from context (#536)
This commit is contained in:
@@ -50,7 +50,6 @@ exports[`init > should match config 1`] = `
|
|||||||
},
|
},
|
||||||
"baseURL": "http://localhost:3000/api/auth",
|
"baseURL": "http://localhost:3000/api/auth",
|
||||||
"createAuthCookie": [Function],
|
"createAuthCookie": [Function],
|
||||||
"db": Kysely {},
|
|
||||||
"internalAdapter": {
|
"internalAdapter": {
|
||||||
"createAccount": [Function],
|
"createAccount": [Function],
|
||||||
"createOAuthUser": [Function],
|
"createOAuthUser": [Function],
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import type { Kysely } from "kysely";
|
|
||||||
import { getAuthTables } from "./db/get-tables";
|
import { getAuthTables } from "./db/get-tables";
|
||||||
import { createKyselyAdapter } from "./adapters/kysely-adapter/dialect";
|
|
||||||
import { getAdapter } from "./db/utils";
|
import { getAdapter } from "./db/utils";
|
||||||
import { hashPassword, verifyPassword } from "./crypto/password";
|
import { hashPassword, verifyPassword } from "./crypto/password";
|
||||||
import { createInternalAdapter } from "./db";
|
import { createInternalAdapter } from "./db";
|
||||||
@@ -30,7 +28,6 @@ export const init = async (options: BetterAuthOptions) => {
|
|||||||
const plugins = options.plugins || [];
|
const plugins = options.plugins || [];
|
||||||
const internalPlugins = getInternalPlugins(options);
|
const internalPlugins = getInternalPlugins(options);
|
||||||
|
|
||||||
const { kysely: db } = await createKyselyAdapter(options);
|
|
||||||
const baseURL = getBaseURL(options.baseURL, options.basePath);
|
const baseURL = getBaseURL(options.baseURL, options.basePath);
|
||||||
|
|
||||||
const secret =
|
const secret =
|
||||||
@@ -103,7 +100,6 @@ export const init = async (options: BetterAuthOptions) => {
|
|||||||
logger: createLogger({
|
logger: createLogger({
|
||||||
disabled: options.logger?.disabled || false,
|
disabled: options.logger?.disabled || false,
|
||||||
}),
|
}),
|
||||||
db,
|
|
||||||
uuid: generateId,
|
uuid: generateId,
|
||||||
secondaryStorage: options.secondaryStorage,
|
secondaryStorage: options.secondaryStorage,
|
||||||
password: {
|
password: {
|
||||||
@@ -134,7 +130,6 @@ export type AuthContext = {
|
|||||||
socialProviders: OAuthProvider[];
|
socialProviders: OAuthProvider[];
|
||||||
authCookies: BetterAuthCookies;
|
authCookies: BetterAuthCookies;
|
||||||
logger: ReturnType<typeof createLogger>;
|
logger: ReturnType<typeof createLogger>;
|
||||||
db: Kysely<any> | null;
|
|
||||||
rateLimit: {
|
rateLimit: {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
window: number;
|
window: number;
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ export const getOrgAdapter = (
|
|||||||
/**
|
/**
|
||||||
* @requires db
|
* @requires db
|
||||||
*/
|
*/
|
||||||
findFullOrganization: async (organizationId: string, db?: Kysely<any>) => {
|
findFullOrganization: async (organizationId: string) => {
|
||||||
const [org, invitations, members] = await Promise.all([
|
const [org, invitations, members] = await Promise.all([
|
||||||
adapter.findOne<Organization>({
|
adapter.findOne<Organization>({
|
||||||
model: "organization",
|
model: "organization",
|
||||||
|
|||||||
@@ -241,10 +241,7 @@ export const getFullOrganization = createAuthEndpoint(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const adapter = getOrgAdapter(ctx.context, ctx.context.orgOptions);
|
const adapter = getOrgAdapter(ctx.context, ctx.context.orgOptions);
|
||||||
const organization = await adapter.findFullOrganization(
|
const organization = await adapter.findFullOrganization(organizationId);
|
||||||
organizationId,
|
|
||||||
ctx.context.db || undefined,
|
|
||||||
);
|
|
||||||
if (!organization) {
|
if (!organization) {
|
||||||
throw new APIError("BAD_REQUEST", {
|
throw new APIError("BAD_REQUEST", {
|
||||||
message: "Organization not found",
|
message: "Organization not found",
|
||||||
@@ -293,10 +290,7 @@ export const setActiveOrganization = createAuthEndpoint(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
await adapter.setActiveOrganization(session.session.id, organizationId);
|
await adapter.setActiveOrganization(session.session.id, organizationId);
|
||||||
const organization = await adapter.findFullOrganization(
|
const organization = await adapter.findFullOrganization(organizationId);
|
||||||
organizationId,
|
|
||||||
ctx.context.db || undefined,
|
|
||||||
);
|
|
||||||
return ctx.json(organization);
|
return ctx.json(organization);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user