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