updates
This commit is contained in:
@@ -47,14 +47,12 @@ export const Route = createFileRoute("/api/events/$")({
|
||||
"ServerEvents | Closing connection",
|
||||
context?.userAuthId
|
||||
);
|
||||
controller.close();
|
||||
} catch (e) {
|
||||
logger.error("ServerEvents | Error closing controller", e);
|
||||
}
|
||||
};
|
||||
|
||||
request.signal?.addEventListener("abort", cleanup);
|
||||
|
||||
return cleanup;
|
||||
},
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ export const Route = createFileRoute(
|
||||
try {
|
||||
const { collection, recordId, file } = params;
|
||||
const pocketbaseUrl =
|
||||
import.meta.env.POCKETBASE_URL || "http://127.0.0.1:8090";
|
||||
process.env.POCKETBASE_URL || "http://127.0.0.1:8090";
|
||||
const fileUrl = `${pocketbaseUrl}/api/files/${collection}/${recordId}/${file}`;
|
||||
|
||||
logger.info("File proxy", {
|
||||
|
||||
@@ -19,7 +19,7 @@ const AdminPage = () => {
|
||||
label="Open Pocketbase"
|
||||
Icon={DatabaseIcon}
|
||||
onClick={() =>
|
||||
window.location.replace(import.meta.env.POCKETBASE_URL! + "/_/")
|
||||
window.location.replace(process.env.POCKETBASE_URL! + "/_/")
|
||||
}
|
||||
/>
|
||||
<ListLink
|
||||
|
||||
@@ -88,7 +88,7 @@ export const getUnenrolledTeams = createServerFn()
|
||||
|
||||
export const getFreeAgents = createServerFn()
|
||||
.inputValidator(z.string())
|
||||
.middleware([superTokensAdminFunctionMiddleware])
|
||||
.middleware([superTokensFunctionMiddleware])
|
||||
.handler(async ({ data: tournamentId }) =>
|
||||
toServerResult(() => pbAdmin.getFreeAgents(tournamentId))
|
||||
);
|
||||
|
||||
@@ -37,6 +37,7 @@ export function useServerEvents() {
|
||||
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window === 'undefined') return;
|
||||
if (!user?.id) return;
|
||||
|
||||
shouldConnectRef.current = true;
|
||||
|
||||
@@ -13,7 +13,7 @@ export const backendConfig = (): TypeInput => {
|
||||
framework: "custom",
|
||||
supertokens: {
|
||||
connectionURI:
|
||||
import.meta.env.SUPERTOKENS_URI || "https://try.supertokens.io",
|
||||
process.env.SUPERTOKENS_URI || "https://try.supertokens.io",
|
||||
},
|
||||
appInfo,
|
||||
recipeList: [
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { Twilio } from "twilio";
|
||||
|
||||
const accountSid = import.meta.env.TWILIO_ACCOUNT_SID!;
|
||||
const authToken = import.meta.env.TWILIO_AUTH_TOKEN!;
|
||||
const serviceSid = import.meta.env.TWILIO_SERVICE_SID!;
|
||||
const accountSid = process.env.TWILIO_ACCOUNT_SID!;
|
||||
const authToken = process.env.TWILIO_AUTH_TOKEN!;
|
||||
const serviceSid = process.env.TWILIO_SERVICE_SID!;
|
||||
|
||||
let client: Twilio;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
createMiddleware,
|
||||
createServerFn,
|
||||
createServerOnlyFn,
|
||||
} from "@tanstack/react-start";
|
||||
import { getRequest, setResponseHeader } from "@tanstack/react-start/server";
|
||||
import { redirect as redirect } from "@tanstack/react-router";
|
||||
@@ -13,7 +14,23 @@ import { refreshSession } from "supertokens-node/recipe/session";
|
||||
|
||||
const logger = new Logger("Middleware");
|
||||
|
||||
export const verifySuperTokensSession = async (
|
||||
function createNodeRequest(request: Request) {
|
||||
const cookies = request.headers.get('cookie') || '';
|
||||
|
||||
return {
|
||||
getHeaderValue: (key: string) => {
|
||||
return request.headers.get(key) || undefined;
|
||||
},
|
||||
getCookieValue: (key: string) => {
|
||||
const match = cookies.match(new RegExp(`(^| )${key}=([^;]+)`));
|
||||
return match ? match[2] : undefined;
|
||||
},
|
||||
getMethod: () => request.method,
|
||||
getOriginalURL: () => request.url,
|
||||
};
|
||||
}
|
||||
|
||||
const verifySuperTokensSession = async (
|
||||
request: Request
|
||||
) => {
|
||||
let session = await getSessionForStart(request, { sessionRequired: false });
|
||||
@@ -22,14 +39,18 @@ export const verifySuperTokensSession = async (
|
||||
logger.info("Session needs refresh");
|
||||
|
||||
try {
|
||||
const refreshedSession = await refreshSession(request, {
|
||||
|
||||
const nodeRequest = createNodeRequest(request);
|
||||
const nodeResponse = {
|
||||
setHeader: (key: string, value: string) => {
|
||||
setResponseHeader(key, value);
|
||||
},
|
||||
setCookie: (cookie: string) => {
|
||||
setResponseHeader('Set-Cookie', cookie);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const refreshedSession = await refreshSession(nodeRequest, nodeResponse);
|
||||
if (refreshedSession) {
|
||||
session = await getSessionForStart(request, { sessionRequired: false });
|
||||
}
|
||||
@@ -71,7 +92,7 @@ export const verifySuperTokensSession = async (
|
||||
};
|
||||
};
|
||||
|
||||
export const getSessionContext = async (request: Request, options?: { isServerFunction?: boolean }) => {
|
||||
export const getSessionContext = createServerOnlyFn(async (request: Request, options?: { isServerFunction?: boolean }) => {
|
||||
const session = await verifySuperTokensSession(request);
|
||||
|
||||
if (session.context.session?.tryRefresh) {
|
||||
@@ -100,7 +121,7 @@ export const getSessionContext = async (request: Request, options?: { isServerFu
|
||||
};
|
||||
|
||||
return context;
|
||||
};
|
||||
});
|
||||
|
||||
export const superTokensRequestMiddleware = createMiddleware({
|
||||
type: "request",
|
||||
|
||||
Reference in New Issue
Block a user