Merge remote-tracking branch 'origin/main' into feat/astro-adapter

This commit is contained in:
dswbx
2024-11-29 20:14:31 +01:00
3 changed files with 13 additions and 5 deletions

View File

@@ -3,7 +3,7 @@
"type": "module", "type": "module",
"sideEffects": false, "sideEffects": false,
"bin": "./dist/cli/index.js", "bin": "./dist/cli/index.js",
"version": "0.1.0", "version": "0.1.1",
"scripts": { "scripts": {
"build:all": "bun run build && bun run build:cli", "build:all": "bun run build && bun run build:cli",
"dev": "vite", "dev": "vite",

View File

@@ -1,5 +1,5 @@
import type { AppAuth } from "auth"; import type { AppAuth } from "auth";
import type { ClassController } from "core"; import { type ClassController, isDebug } from "core";
import { Hono, type MiddlewareHandler } from "hono"; import { Hono, type MiddlewareHandler } from "hono";
export class AuthController implements ClassController { export class AuthController implements ClassController {
@@ -10,8 +10,16 @@ export class AuthController implements ClassController {
} }
getMiddleware: MiddlewareHandler = async (c, next) => { getMiddleware: MiddlewareHandler = async (c, next) => {
const user = await this.auth.authenticator.resolveAuthFromRequest(c); // @todo: ONLY HOTFIX
this.auth.ctx.guard.setUserContext(user); const url = new URL(c.req.url);
const last = url.pathname.split("/")?.pop();
const ext = last?.includes(".") ? last.split(".")?.pop() : undefined;
if (ext) {
isDebug() && console.log("Skipping auth", { ext }, url.pathname);
} else {
const user = await this.auth.authenticator.resolveAuthFromRequest(c);
this.auth.ctx.guard.setUserContext(user);
}
await next(); await next();
}; };

View File

@@ -228,9 +228,9 @@ export class Authenticator<Strategies extends Record<string, Strategy> = Record<
async requestCookieRefresh(c: Context) { async requestCookieRefresh(c: Context) {
if (this.config.cookie.renew) { if (this.config.cookie.renew) {
console.log("renewing cookie", c.req.url);
const token = await this.getAuthCookie(c); const token = await this.getAuthCookie(c);
if (token) { if (token) {
console.log("renewing cookie", c.req.url);
await this.setAuthCookie(c, token); await this.setAuthCookie(c, token);
} }
} }