Skip to content

Commit 203f346

Browse files
fix(env): base url reading from vercel deployment of local next
1 parent ad651a2 commit 203f346

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

src/edgedb/auth.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import createAuth from "@edgedb/auth-nextjs/app";
22
import { client } from "./client";
3+
import { getBaseUrl } from "@/server/baseUrl";
34

45
export const auth = createAuth(client, {
5-
baseUrl: "http://localhost:3000",
6+
baseUrl: getBaseUrl(),
67
passwordResetPath: "/reset-password",
78
});

src/env.mjs

+4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { createEnv } from "@t3-oss/env-nextjs";
22
import { z } from "zod";
3+
import { vercel } from "@t3-oss/env-nextjs/presets";
34

45
export const env = createEnv({
6+
extends: [vercel],
57
/**
68
* Specify your server-side environment variables schema here. This way you can ensure the app
79
* isn't built with invalid env vars.
810
*/
911
server: {
1012
NODE_ENV: z.enum(["development", "test", "production"]),
13+
PORT: z.coerce.number(), // From `next dev -p $PORT`
1114
EDGEDB_DSN: z.string(),
1215
},
1316

@@ -26,6 +29,7 @@ export const env = createEnv({
2629
*/
2730
runtimeEnv: {
2831
NODE_ENV: process.env.NODE_ENV,
32+
PORT: process.env.PORT,
2933
EDGEDB_DSN: process.env.EDGEDB_DSN,
3034
// NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
3135
},

src/server/baseUrl.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { env } from "@/env.mjs";
2+
3+
export function getBaseUrl() {
4+
if (typeof window !== "undefined") return "";
5+
if (env.VERCEL_URL) return `https://${env.VERCEL_URL}`;
6+
return `http://localhost:${env.PORT}`;
7+
}

src/trpc/shared.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@ import { type inferRouterInputs, type inferRouterOutputs } from "@trpc/server";
22
import superjson from "superjson";
33

44
import { type AppRouter } from "@/server/api/root";
5+
import { getBaseUrl } from "@/server/baseUrl";
56

67
export const transformer = superjson;
78

8-
function getBaseUrl() {
9-
if (typeof window !== "undefined") return "";
10-
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`;
11-
return `http://localhost:${process.env.PORT ?? 3000}`;
12-
}
13-
149
export function getUrl() {
1510
return getBaseUrl() + "/api/trpc";
1611
}

0 commit comments

Comments
 (0)