mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
fix(plugin): 🐛 Fix misleading error message related to plugin initialization
This commit is contained in:
parent
11bb0a6f49
commit
3b704b4c8c
3
app.ts
3
app.ts
|
|
@ -138,7 +138,8 @@ export const appFactory = async () => {
|
|||
serverLogger.fatal`Put your configuration at ${chalk.blueBright(
|
||||
"plugins.config.<plugin-name>",
|
||||
)}`;
|
||||
throw new Error("Plugin configuration is invalid");
|
||||
|
||||
await Bun.sleep(Number.POSITIVE_INFINITY);
|
||||
}
|
||||
|
||||
// biome-ignore lint/complexity/useLiteralKeys: AddToApp is a private method
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { Hooks, Plugin } from "@versia/kit";
|
||||
import chalk from "chalk";
|
||||
import { z } from "zod";
|
||||
import { User } from "@versia/kit/db";
|
||||
import authorizeRoute from "./routes/authorize.ts";
|
||||
import jwksRoute from "./routes/jwks.ts";
|
||||
import ssoLoginCallbackRoute from "./routes/oauth/callback.ts";
|
||||
|
|
@ -26,8 +27,12 @@ const plugin = new Plugin(
|
|||
}),
|
||||
)
|
||||
.default([]),
|
||||
keys: z.object({
|
||||
public: z.string().transform(async (v) => {
|
||||
keys: z
|
||||
.object({
|
||||
public: z
|
||||
.string()
|
||||
.min(1)
|
||||
.transform(async (v) => {
|
||||
try {
|
||||
return await crypto.subtle.importKey(
|
||||
"spki",
|
||||
|
|
@ -38,11 +43,14 @@ const plugin = new Plugin(
|
|||
);
|
||||
} catch {
|
||||
throw new Error(
|
||||
`Public key at keys.public is invalid. Run the ${chalk.bold("generate-keys")} command to generate a new keypair`,
|
||||
"Public key at oidc.keys.public is invalid",
|
||||
);
|
||||
}
|
||||
}),
|
||||
private: z.string().transform(async (v) => {
|
||||
private: z
|
||||
.string()
|
||||
.min(1)
|
||||
.transform(async (v) => {
|
||||
try {
|
||||
return await crypto.subtle.importKey(
|
||||
"pkcs8",
|
||||
|
|
@ -53,10 +61,25 @@ const plugin = new Plugin(
|
|||
);
|
||||
} catch {
|
||||
throw new Error(
|
||||
`Private key at keys.private is invalid. Run the ${chalk.bold("generate-keys")} command to generate a new keypair`,
|
||||
"Private key at oidc.keys.private is invalid",
|
||||
);
|
||||
}
|
||||
}),
|
||||
})
|
||||
.optional()
|
||||
.transform(async (v, ctx) => {
|
||||
if (!(v?.private && v?.public)) {
|
||||
const { public_key, private_key } =
|
||||
await User.generateKeys();
|
||||
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `Keys are missing, please add the following to your config:\n\nkeys.public: ${chalk.gray(public_key)}\nkeys.private: ${chalk.gray(private_key)}
|
||||
`,
|
||||
});
|
||||
}
|
||||
|
||||
return v as Exclude<typeof v, undefined>;
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { getLogger } from "@logtape/logtape";
|
||||
import chalk from "chalk";
|
||||
import { User } from "~/classes/database/user";
|
||||
import type { Config } from "~/packages/config-manager";
|
||||
|
||||
export const checkConfig = async (config: Config) => {
|
||||
|
|
@ -68,8 +69,15 @@ const checkFederationConfig = async (config: Config) => {
|
|||
const logger = getLogger("server");
|
||||
|
||||
if (!(config.instance.keys.public && config.instance.keys.private)) {
|
||||
logger.fatal`The federation keys are not set in the config at instance.keys.public and instance.keys.private`;
|
||||
logger.fatal`You can generate a keypair using the CLI command ${chalk.bold("generate-keys")}`;
|
||||
logger.fatal`The federation keys are not set in the config`;
|
||||
logger.fatal`Below are generated keys for you to copy in the config at instance.keys.public and instance.keys.private`;
|
||||
|
||||
// Generate a key for them
|
||||
const { public_key, private_key } = await User.generateKeys();
|
||||
|
||||
logger.fatal`Generated public key: ${chalk.gray(public_key)}`;
|
||||
logger.fatal`Generated private key: ${chalk.gray(private_key)}`;
|
||||
|
||||
// Hang until Ctrl+C is pressed
|
||||
await Bun.sleep(Number.POSITIVE_INFINITY);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue