BA
Better Auth•4d ago
bxr

openapi not showing commands

I set up the openAPI plugin as showed in the docs, but the commands are not showing as shown in the attached video. I am using ElysiaJS and drizzleorm my auth:
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
}),
emailAndPassword: {
enabled: true,
password: {
hash: Bun.password.hash,
verify: ({ password, hash }) => Bun.password.verify(password, hash),
},
},
socialProviders: {
discord: {
clientId: process.env.DISCORD_CLIENT_ID as string,
clientSecret: process.env.DISCORD_CLIENT_SECRET as string,
},
},
plugins: [openAPI()],
user: {
additionalFields: {
role: {
type: "string",
required: false,
defaultValue: "user",
input: false,
},
},
},
});

export const betterAuthView = (context: Context) => {
const BETTER_AUTH_ACCEPT_METHODS = ["POST", "GET"];
if (BETTER_AUTH_ACCEPT_METHODS.includes(context.request.method)) {
console.log(context.request);
return auth.handler(context.request);
}

context.error(405);
};

export const authService = new Elysia().all("/api/auth/*", betterAuthView);
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
}),
emailAndPassword: {
enabled: true,
password: {
hash: Bun.password.hash,
verify: ({ password, hash }) => Bun.password.verify(password, hash),
},
},
socialProviders: {
discord: {
clientId: process.env.DISCORD_CLIENT_ID as string,
clientSecret: process.env.DISCORD_CLIENT_SECRET as string,
},
},
plugins: [openAPI()],
user: {
additionalFields: {
role: {
type: "string",
required: false,
defaultValue: "user",
input: false,
},
},
},
});

export const betterAuthView = (context: Context) => {
const BETTER_AUTH_ACCEPT_METHODS = ["POST", "GET"];
if (BETTER_AUTH_ACCEPT_METHODS.includes(context.request.method)) {
console.log(context.request);
return auth.handler(context.request);
}

context.error(405);
};

export const authService = new Elysia().all("/api/auth/*", betterAuthView);
import { Elysia } from "elysia";
import { listingsRouter } from "./routes/listings";
import { authService } from "./libs/auth/auth";

const app = new Elysia()
.use(authService)
.use(listingsRouter) // Mounts listings routes
.onError(({ code, error, set }) => {
console.log(error);
if (code === "VALIDATION") {
set.status = 400;
return { message: "Bad Request", details: error.message };
}
// Default status set in route-specific handlers
return { message: error.message };
})
.listen(8080);

console.log(
`🦊 Mercury backend running at ${app.server?.hostname}:${app.server?.port}`,
);
import { Elysia } from "elysia";
import { listingsRouter } from "./routes/listings";
import { authService } from "./libs/auth/auth";

const app = new Elysia()
.use(authService)
.use(listingsRouter) // Mounts listings routes
.onError(({ code, error, set }) => {
console.log(error);
if (code === "VALIDATION") {
set.status = 400;
return { message: "Bad Request", details: error.message };
}
// Default status set in route-specific handlers
return { message: error.message };
})
.listen(8080);

console.log(
`🦊 Mercury backend running at ${app.server?.hostname}:${app.server?.port}`,
);
Solution:
update to 1.2 beta
Jump to solution
4 Replies
Solution
bekacru
bekacru•4d ago
update to 1.2 beta
bxr
bxrOP•4d ago
thanks that worked. since we are here. i tried signing up through postman
# SERVER_ERROR: 1 | // src/error/index.ts
2 | var BetterAuthError = class extends Error {
3 | constructor(message, cause) {
4 | super(message);
^
BetterAuthError: [# Drizzle Adapter]: The model "user" was not found in the schema object. Please pass the schema directly to the adapter options.
cause: undefined,
# SERVER_ERROR: 1 | // src/error/index.ts
2 | var BetterAuthError = class extends Error {
3 | constructor(message, cause) {
4 | super(message);
^
BetterAuthError: [# Drizzle Adapter]: The model "user" was not found in the schema object. Please pass the schema directly to the adapter options.
cause: undefined,
i get this error, but i am using generated schemas from the better-auth cli
export const user = pgTable("user", {
id: text("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
emailVerified: boolean("email_verified").notNull(),
image: text("image"),
createdAt: timestamp("created_at").notNull(),
updatedAt: timestamp("updated_at").notNull(),
role: text("role"),
banned: boolean("banned"),
banReason: text("ban_reason"),
banExpires: timestamp("ban_expires"),
});
export const user = pgTable("user", {
id: text("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
emailVerified: boolean("email_verified").notNull(),
image: text("image"),
createdAt: timestamp("created_at").notNull(),
updatedAt: timestamp("updated_at").notNull(),
role: text("role"),
banned: boolean("banned"),
banReason: text("ban_reason"),
banExpires: timestamp("ban_expires"),
});
bekacru
bekacru•4d ago
try to pass the schema directly the adapter
drizzleAdapter({
schema: {
user,
...restOfYourSchema
}
})
drizzleAdapter({
schema: {
user,
...restOfYourSchema
}
})
bxr
bxrOP•4d ago
that worked 🙂 ty :salute:

Did you find this page helpful?