fixed auth middleware

This commit is contained in:
dswbx
2025-01-11 08:28:46 +01:00
parent c06ba061f0
commit 0d945ab45b
3 changed files with 13 additions and 5 deletions

View File

@@ -276,6 +276,10 @@ export class AppAuth extends Module<typeof authConfigSchema> {
}
async createUser({ email, password, ...additional }: CreateUserPayload): Promise<DB["users"]> {
if (!this.enabled) {
throw new Error("Cannot create user, auth not enabled");
}
const strategy = "password";
const pw = this.authenticator.strategy(strategy) as PasswordStrategy;
const strategy_value = await pw.hash(password);

View File

@@ -21,12 +21,16 @@ async function resolveAuth(app: ServerEnv["Variables"]["app"], c: Context<Server
authenticator.requestCookieRefresh(c);
}
export function shouldSkipAuth(c: { req: Request }) {
return new URL(c.req.url).pathname.startsWith(config.server.assets_path);
export function shouldSkipAuth(req: Request) {
const skip = new URL(req.url).pathname.startsWith(config.server.assets_path);
if (skip) {
//console.log("skip auth for", req.url);
}
return skip;
}
export const auth = createMiddleware<ServerEnv>(async (c, next) => {
if (!shouldSkipAuth) {
if (!shouldSkipAuth(c.req.raw)) {
// make sure to only register once
if (c.get("auth_registered")) {
return;