auth fix?
This commit is contained in:
@@ -14,6 +14,8 @@ import { serverFnLoggingMiddleware } from "./activities";
|
||||
import { pbAdmin } from "@/lib/pocketbase/client";
|
||||
const logger = new Logger("Middleware");
|
||||
|
||||
export const PUBLIC_ROUTES = ["/login", "/logout", "/refresh-session"];
|
||||
|
||||
const verifySuperTokensSession = async (
|
||||
request: Request
|
||||
) => {
|
||||
@@ -55,12 +57,18 @@ export const getSessionContext = createServerOnlyFn(async (request: Request, opt
|
||||
if (options?.isServerFunction) {
|
||||
throw new Error("SESSION_REFRESH_REQUIRED");
|
||||
}
|
||||
|
||||
|
||||
const url = new URL(request.url);
|
||||
const from = encodeURIComponent(url.pathname + url.search);
|
||||
throw redirect({
|
||||
to: "/refresh-session",
|
||||
search: { redirect: from }
|
||||
|
||||
if (PUBLIC_ROUTES.some((route) => url.pathname.startsWith(route))) {
|
||||
throw new Error("Unauthenticated");
|
||||
}
|
||||
|
||||
const from = url.pathname + url.search;
|
||||
|
||||
throw redirect({
|
||||
to: "/refresh-session",
|
||||
search: from === "/" ? {} : { redirect: from },
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user