@convex-dev/better-auth 0.7.0-alpha.4 → 0.7.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/react-start/index.d.ts +6 -2
- package/dist/commonjs/react-start/index.d.ts.map +1 -1
- package/dist/commonjs/react-start/index.js +17 -13
- package/dist/commonjs/react-start/index.js.map +1 -1
- package/dist/esm/react-start/index.d.ts +6 -2
- package/dist/esm/react-start/index.d.ts.map +1 -1
- package/dist/esm/react-start/index.js +17 -13
- package/dist/esm/react-start/index.js.map +1 -1
- package/package.json +1 -1
- package/src/react-start/index.ts +27 -20
- package/src/react-start/vite-env.d.ts +2 -0
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { betterAuth } from "better-auth";
|
|
2
2
|
import { GenericActionCtx } from "convex/server";
|
|
3
3
|
export declare const getCookieName: (createAuth: (ctx: GenericActionCtx<any>) => ReturnType<typeof betterAuth>) => Promise<string>;
|
|
4
|
-
export declare const fetchSession: <T extends (ctx: GenericActionCtx<any>) => ReturnType<typeof betterAuth>>(
|
|
4
|
+
export declare const fetchSession: <T extends (ctx: GenericActionCtx<any>) => ReturnType<typeof betterAuth>>(request: Request, opts?: {
|
|
5
|
+
convexSiteUrl: string;
|
|
6
|
+
verbose?: boolean;
|
|
7
|
+
}) => Promise<{
|
|
5
8
|
session: ReturnType<T>["$Infer"]["Session"] | null;
|
|
6
9
|
}>;
|
|
7
|
-
export declare const reactStartHandler: (request: Request, opts
|
|
10
|
+
export declare const reactStartHandler: (request: Request, opts?: {
|
|
8
11
|
convexSiteUrl: string;
|
|
12
|
+
verbose?: boolean;
|
|
9
13
|
}) => Promise<Response>;
|
|
10
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react-start/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react-start/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGjD,eAAO,MAAM,aAAa,GACxB,YAAY,CAAC,GAAG,EAAE,gBAAgB,CAAC,GAAG,CAAC,KAAK,UAAU,CAAC,OAAO,UAAU,CAAC,oBAM1E,CAAC;AAiBF,eAAO,MAAM,YAAY,GACvB,CAAC,SAAS,CAAC,GAAG,EAAE,gBAAgB,CAAC,GAAG,CAAC,KAAK,UAAU,CAAC,OAAO,UAAU,CAAC,EAEvE,SAAS,OAAO,EAChB,OAAO;IACL,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;;EAmBF,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,SAAS,OAAO,EAChB,OAAO;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,sBAUpD,CAAC"}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { createCookieGetter } from "better-auth/cookies";
|
|
2
2
|
import { betterFetch } from "@better-fetch/fetch";
|
|
3
3
|
import { JWT_COOKIE_NAME } from "../plugins/convex";
|
|
4
|
-
const requireBaseURL = (createAuth) => {
|
|
5
|
-
const baseUrl = createAuth({}).options.baseURL;
|
|
6
|
-
if (!baseUrl) {
|
|
7
|
-
throw new Error("No baseURL found in Better Auth config. baseUrl should be set to your Convex Site URL.");
|
|
8
|
-
}
|
|
9
|
-
return baseUrl;
|
|
10
|
-
};
|
|
11
4
|
export const getCookieName = async (createAuth) => {
|
|
12
|
-
// Require baseURL here because it's protocol determines cookie secure mode,
|
|
13
|
-
// and must be set to ensure cookies work between TanStack and Convex.
|
|
14
|
-
requireBaseURL(createAuth);
|
|
15
5
|
const auth = createAuth({});
|
|
16
6
|
const createCookie = createCookieGetter(auth.options);
|
|
17
7
|
const cookie = createCookie(JWT_COOKIE_NAME);
|
|
18
8
|
return cookie.name;
|
|
19
9
|
};
|
|
20
|
-
|
|
10
|
+
const requireConvexSiteUrl = (opts) => {
|
|
11
|
+
const baseURL = opts?.convexSiteUrl ?? import.meta.env.VITE_CONVEX_SITE_URL;
|
|
12
|
+
if (!baseURL) {
|
|
13
|
+
throw new Error("VITE_CONVEX_SITE_URL is not set");
|
|
14
|
+
}
|
|
15
|
+
if (opts?.verbose) {
|
|
16
|
+
console.log(`${opts.calledFrom} convexSiteUrl`, baseURL);
|
|
17
|
+
}
|
|
18
|
+
return baseURL;
|
|
19
|
+
};
|
|
20
|
+
export const fetchSession = async (request, opts) => {
|
|
21
21
|
if (!request) {
|
|
22
22
|
throw new Error("No request found");
|
|
23
23
|
}
|
|
24
24
|
const { data: session } = await betterFetch("/api/auth/get-session", {
|
|
25
|
-
baseURL:
|
|
25
|
+
baseURL: requireConvexSiteUrl({ ...opts, calledFrom: "fetchSession" }),
|
|
26
26
|
headers: {
|
|
27
27
|
cookie: request.headers.get("cookie") ?? "",
|
|
28
28
|
},
|
|
@@ -33,7 +33,11 @@ export const fetchSession = async (createAuth, request) => {
|
|
|
33
33
|
};
|
|
34
34
|
export const reactStartHandler = (request, opts) => {
|
|
35
35
|
const requestUrl = new URL(request.url);
|
|
36
|
-
const
|
|
36
|
+
const convexSiteUrl = requireConvexSiteUrl({
|
|
37
|
+
...opts,
|
|
38
|
+
calledFrom: "reactStartHandler",
|
|
39
|
+
});
|
|
40
|
+
const nextUrl = `${convexSiteUrl}${requestUrl.pathname}${requestUrl.search}`;
|
|
37
41
|
request.headers.set("accept-encoding", "application/json");
|
|
38
42
|
return fetch(nextUrl, new Request(request, { redirect: "manual" }));
|
|
39
43
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react-start/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react-start/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAChC,UAAyE,EACzE,EAAE;IACF,MAAM,IAAI,GAAG,UAAU,CAAC,EAAS,CAAC,CAAC;IACnC,MAAM,YAAY,GAAG,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACtD,MAAM,MAAM,GAAG,YAAY,CAAC,eAAe,CAAC,CAAC;IAC7C,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC,CAAC;AAEF,MAAM,oBAAoB,GAAG,CAAC,IAI7B,EAAE,EAAE;IACH,MAAM,OAAO,GAAG,IAAI,EAAE,aAAa,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,oBAAoB,CAAC;IAC5E,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IACD,IAAI,IAAI,EAAE,OAAO,EAAE,CAAC;QAClB,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,UAAU,gBAAgB,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAG/B,OAAgB,EAChB,IAGC,EACD,EAAE;IAGF,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;IACD,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,WAAW,CACzC,uBAAuB,EACvB;QACE,OAAO,EAAE,oBAAoB,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC;QACtE,OAAO,EAAE;YACP,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE;SAC5C;KACF,CACF,CAAC;IACF,OAAO;QACL,OAAO;KACR,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,OAAgB,EAChB,IAAmD,EACnD,EAAE;IACF,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACxC,MAAM,aAAa,GAAG,oBAAoB,CAAC;QACzC,GAAG,IAAI;QACP,UAAU,EAAE,mBAAmB;KAChC,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,GAAG,aAAa,GAAG,UAAU,CAAC,QAAQ,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;IAC7E,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,kBAAkB,CAAC,CAAC;IAC3D,OAAO,KAAK,CAAC,OAAO,EAAE,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;AACtE,CAAC,CAAC"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { betterAuth } from "better-auth";
|
|
2
2
|
import { GenericActionCtx } from "convex/server";
|
|
3
3
|
export declare const getCookieName: (createAuth: (ctx: GenericActionCtx<any>) => ReturnType<typeof betterAuth>) => Promise<string>;
|
|
4
|
-
export declare const fetchSession: <T extends (ctx: GenericActionCtx<any>) => ReturnType<typeof betterAuth>>(
|
|
4
|
+
export declare const fetchSession: <T extends (ctx: GenericActionCtx<any>) => ReturnType<typeof betterAuth>>(request: Request, opts?: {
|
|
5
|
+
convexSiteUrl: string;
|
|
6
|
+
verbose?: boolean;
|
|
7
|
+
}) => Promise<{
|
|
5
8
|
session: ReturnType<T>["$Infer"]["Session"] | null;
|
|
6
9
|
}>;
|
|
7
|
-
export declare const reactStartHandler: (request: Request, opts
|
|
10
|
+
export declare const reactStartHandler: (request: Request, opts?: {
|
|
8
11
|
convexSiteUrl: string;
|
|
12
|
+
verbose?: boolean;
|
|
9
13
|
}) => Promise<Response>;
|
|
10
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react-start/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react-start/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGjD,eAAO,MAAM,aAAa,GACxB,YAAY,CAAC,GAAG,EAAE,gBAAgB,CAAC,GAAG,CAAC,KAAK,UAAU,CAAC,OAAO,UAAU,CAAC,oBAM1E,CAAC;AAiBF,eAAO,MAAM,YAAY,GACvB,CAAC,SAAS,CAAC,GAAG,EAAE,gBAAgB,CAAC,GAAG,CAAC,KAAK,UAAU,CAAC,OAAO,UAAU,CAAC,EAEvE,SAAS,OAAO,EAChB,OAAO;IACL,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;;EAmBF,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,SAAS,OAAO,EAChB,OAAO;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,sBAUpD,CAAC"}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { createCookieGetter } from "better-auth/cookies";
|
|
2
2
|
import { betterFetch } from "@better-fetch/fetch";
|
|
3
3
|
import { JWT_COOKIE_NAME } from "../plugins/convex/index.js";
|
|
4
|
-
const requireBaseURL = (createAuth) => {
|
|
5
|
-
const baseUrl = createAuth({}).options.baseURL;
|
|
6
|
-
if (!baseUrl) {
|
|
7
|
-
throw new Error("No baseURL found in Better Auth config. baseUrl should be set to your Convex Site URL.");
|
|
8
|
-
}
|
|
9
|
-
return baseUrl;
|
|
10
|
-
};
|
|
11
4
|
export const getCookieName = async (createAuth) => {
|
|
12
|
-
// Require baseURL here because it's protocol determines cookie secure mode,
|
|
13
|
-
// and must be set to ensure cookies work between TanStack and Convex.
|
|
14
|
-
requireBaseURL(createAuth);
|
|
15
5
|
const auth = createAuth({});
|
|
16
6
|
const createCookie = createCookieGetter(auth.options);
|
|
17
7
|
const cookie = createCookie(JWT_COOKIE_NAME);
|
|
18
8
|
return cookie.name;
|
|
19
9
|
};
|
|
20
|
-
|
|
10
|
+
const requireConvexSiteUrl = (opts) => {
|
|
11
|
+
const baseURL = opts?.convexSiteUrl ?? import.meta.env.VITE_CONVEX_SITE_URL;
|
|
12
|
+
if (!baseURL) {
|
|
13
|
+
throw new Error("VITE_CONVEX_SITE_URL is not set");
|
|
14
|
+
}
|
|
15
|
+
if (opts?.verbose) {
|
|
16
|
+
console.log(`${opts.calledFrom} convexSiteUrl`, baseURL);
|
|
17
|
+
}
|
|
18
|
+
return baseURL;
|
|
19
|
+
};
|
|
20
|
+
export const fetchSession = async (request, opts) => {
|
|
21
21
|
if (!request) {
|
|
22
22
|
throw new Error("No request found");
|
|
23
23
|
}
|
|
24
24
|
const { data: session } = await betterFetch("/api/auth/get-session", {
|
|
25
|
-
baseURL:
|
|
25
|
+
baseURL: requireConvexSiteUrl({ ...opts, calledFrom: "fetchSession" }),
|
|
26
26
|
headers: {
|
|
27
27
|
cookie: request.headers.get("cookie") ?? "",
|
|
28
28
|
},
|
|
@@ -33,7 +33,11 @@ export const fetchSession = async (createAuth, request) => {
|
|
|
33
33
|
};
|
|
34
34
|
export const reactStartHandler = (request, opts) => {
|
|
35
35
|
const requestUrl = new URL(request.url);
|
|
36
|
-
const
|
|
36
|
+
const convexSiteUrl = requireConvexSiteUrl({
|
|
37
|
+
...opts,
|
|
38
|
+
calledFrom: "reactStartHandler",
|
|
39
|
+
});
|
|
40
|
+
const nextUrl = `${convexSiteUrl}${requestUrl.pathname}${requestUrl.search}`;
|
|
37
41
|
request.headers.set("accept-encoding", "application/json");
|
|
38
42
|
return fetch(nextUrl, new Request(request, { redirect: "manual" }));
|
|
39
43
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react-start/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react-start/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAChC,UAAyE,EACzE,EAAE;IACF,MAAM,IAAI,GAAG,UAAU,CAAC,EAAS,CAAC,CAAC;IACnC,MAAM,YAAY,GAAG,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACtD,MAAM,MAAM,GAAG,YAAY,CAAC,eAAe,CAAC,CAAC;IAC7C,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC,CAAC;AAEF,MAAM,oBAAoB,GAAG,CAAC,IAI7B,EAAE,EAAE;IACH,MAAM,OAAO,GAAG,IAAI,EAAE,aAAa,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,oBAAoB,CAAC;IAC5E,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IACD,IAAI,IAAI,EAAE,OAAO,EAAE,CAAC;QAClB,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,UAAU,gBAAgB,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAG/B,OAAgB,EAChB,IAGC,EACD,EAAE;IAGF,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;IACD,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,WAAW,CACzC,uBAAuB,EACvB;QACE,OAAO,EAAE,oBAAoB,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC;QACtE,OAAO,EAAE;YACP,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE;SAC5C;KACF,CACF,CAAC;IACF,OAAO;QACL,OAAO;KACR,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,OAAgB,EAChB,IAAmD,EACnD,EAAE;IACF,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACxC,MAAM,aAAa,GAAG,oBAAoB,CAAC;QACzC,GAAG,IAAI;QACP,UAAU,EAAE,mBAAmB;KAChC,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,GAAG,aAAa,GAAG,UAAU,CAAC,QAAQ,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;IAC7E,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,kBAAkB,CAAC,CAAC;IAC3D,OAAO,KAAK,CAAC,OAAO,EAAE,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;AACtE,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/react-start/index.ts
CHANGED
|
@@ -4,35 +4,38 @@ import { betterFetch } from "@better-fetch/fetch";
|
|
|
4
4
|
import { GenericActionCtx } from "convex/server";
|
|
5
5
|
import { JWT_COOKIE_NAME } from "../plugins/convex";
|
|
6
6
|
|
|
7
|
-
const requireBaseURL = (
|
|
8
|
-
createAuth: (ctx: GenericActionCtx<any>) => ReturnType<typeof betterAuth>
|
|
9
|
-
) => {
|
|
10
|
-
const baseUrl = createAuth({} as any).options.baseURL;
|
|
11
|
-
if (!baseUrl) {
|
|
12
|
-
throw new Error(
|
|
13
|
-
"No baseURL found in Better Auth config. baseUrl should be set to your Convex Site URL."
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
return baseUrl;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
7
|
export const getCookieName = async (
|
|
20
8
|
createAuth: (ctx: GenericActionCtx<any>) => ReturnType<typeof betterAuth>
|
|
21
9
|
) => {
|
|
22
|
-
// Require baseURL here because it's protocol determines cookie secure mode,
|
|
23
|
-
// and must be set to ensure cookies work between TanStack and Convex.
|
|
24
|
-
requireBaseURL(createAuth);
|
|
25
10
|
const auth = createAuth({} as any);
|
|
26
11
|
const createCookie = createCookieGetter(auth.options);
|
|
27
12
|
const cookie = createCookie(JWT_COOKIE_NAME);
|
|
28
13
|
return cookie.name;
|
|
29
14
|
};
|
|
30
15
|
|
|
16
|
+
const requireConvexSiteUrl = (opts?: {
|
|
17
|
+
calledFrom: string;
|
|
18
|
+
convexSiteUrl?: string;
|
|
19
|
+
verbose?: boolean;
|
|
20
|
+
}) => {
|
|
21
|
+
const baseURL = opts?.convexSiteUrl ?? import.meta.env.VITE_CONVEX_SITE_URL;
|
|
22
|
+
if (!baseURL) {
|
|
23
|
+
throw new Error("VITE_CONVEX_SITE_URL is not set");
|
|
24
|
+
}
|
|
25
|
+
if (opts?.verbose) {
|
|
26
|
+
console.log(`${opts.calledFrom} convexSiteUrl`, baseURL);
|
|
27
|
+
}
|
|
28
|
+
return baseURL;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
31
|
export const fetchSession = async <
|
|
32
32
|
T extends (ctx: GenericActionCtx<any>) => ReturnType<typeof betterAuth>,
|
|
33
33
|
>(
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
request: Request,
|
|
35
|
+
opts?: {
|
|
36
|
+
convexSiteUrl: string;
|
|
37
|
+
verbose?: boolean;
|
|
38
|
+
}
|
|
36
39
|
) => {
|
|
37
40
|
type Session = ReturnType<T>["$Infer"]["Session"];
|
|
38
41
|
|
|
@@ -42,7 +45,7 @@ export const fetchSession = async <
|
|
|
42
45
|
const { data: session } = await betterFetch<Session>(
|
|
43
46
|
"/api/auth/get-session",
|
|
44
47
|
{
|
|
45
|
-
baseURL:
|
|
48
|
+
baseURL: requireConvexSiteUrl({ ...opts, calledFrom: "fetchSession" }),
|
|
46
49
|
headers: {
|
|
47
50
|
cookie: request.headers.get("cookie") ?? "",
|
|
48
51
|
},
|
|
@@ -55,10 +58,14 @@ export const fetchSession = async <
|
|
|
55
58
|
|
|
56
59
|
export const reactStartHandler = (
|
|
57
60
|
request: Request,
|
|
58
|
-
opts
|
|
61
|
+
opts?: { convexSiteUrl: string; verbose?: boolean }
|
|
59
62
|
) => {
|
|
60
63
|
const requestUrl = new URL(request.url);
|
|
61
|
-
const
|
|
64
|
+
const convexSiteUrl = requireConvexSiteUrl({
|
|
65
|
+
...opts,
|
|
66
|
+
calledFrom: "reactStartHandler",
|
|
67
|
+
});
|
|
68
|
+
const nextUrl = `${convexSiteUrl}${requestUrl.pathname}${requestUrl.search}`;
|
|
62
69
|
request.headers.set("accept-encoding", "application/json");
|
|
63
70
|
return fetch(nextUrl, new Request(request, { redirect: "manual" }));
|
|
64
71
|
};
|