chore: remove unused code from context (#536)

This commit is contained in:
Jani
2024-11-15 12:20:57 +01:00
committed by GitHub
parent 93a49c58b4
commit fb37bb1aa7
4 changed files with 3 additions and 15 deletions

View File

@@ -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],

View File

@@ -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;

View File

@@ -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",

View File

@@ -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);
}, },
); );