-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59d7063
commit 2f779fa
Showing
12 changed files
with
233 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,7 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
.yarn/install-state.gz | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.env | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import("./src/server/env.mjs"); | ||
|
||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
experimental: { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { appRouter } from "@/server/api/routers/root"; | ||
import { createTRPCContext } from "@/server/api/trpc"; | ||
import env from "@/server/env.mjs"; | ||
import { fetchRequestHandler } from "@trpc/server/adapters/fetch"; | ||
import { type NextRequest } from "next/server"; | ||
|
||
const handler = (req: NextRequest) => { | ||
return fetchRequestHandler({ | ||
endpoint: "/api/trpc", | ||
req, | ||
router: appRouter, | ||
createContext: () => createTRPCContext(req), | ||
onError: | ||
env.NEXT_PUBLIC_VERCEL_ENV === "production" | ||
? undefined | ||
: ({ path, error }) => { | ||
console.error(`tRPC failed on ${path}: ${error}`); | ||
}, | ||
}); | ||
}; | ||
export { handler as GET, handler as POST }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { t } from "../trpc"; | ||
|
||
const extensionRouter = t.router({ | ||
hello: t.procedure.query(() => { | ||
return { | ||
text: "Hello World!", | ||
}; | ||
}), | ||
}); | ||
|
||
export const appRouter = t.router({ | ||
extension: extensionRouter, | ||
}); | ||
|
||
export type AppRouter = typeof appRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { TRPCError, initTRPC } from "@trpc/server"; | ||
// import { ITRPCContext } from "./@types/trpc"; | ||
// import { | ||
// getFirebaseUser, | ||
// verifyAuthToken, | ||
// } from "./services/firebaseAdminService"; | ||
// import { getAuthBearer, getIpAddress } from "./utils/headers"; | ||
|
||
interface ITRPCContext {} | ||
|
||
// const getLoggedInUser = async (idToken: string | undefined) => { | ||
// if (!idToken) { | ||
// return null; | ||
// } | ||
// try { | ||
// const { uid } = await verifyAuthToken(idToken, true); | ||
// return await getFirebaseUser(uid); | ||
// } catch (error) { | ||
// console.error(error); | ||
// throw new TRPCError({ | ||
// code: "UNAUTHORIZED", | ||
// message: "Firebase authorization failed", | ||
// }); | ||
// } | ||
// }; | ||
|
||
const getAuthBearer = (req: Request) => | ||
req.headers.get("authorization")?.split?.("Bearer ")?.[1]; | ||
|
||
export const createTRPCContext = async ( | ||
req: Request | ||
): Promise<ITRPCContext> => { | ||
const { headers } = req; | ||
const bearerToken = getAuthBearer(req); | ||
// const user = await getLoggedInUser(bearerToken); | ||
|
||
return { | ||
// user, | ||
}; | ||
}; | ||
|
||
export const t = initTRPC | ||
.context<Awaited<ReturnType<typeof createTRPCContext>>>() | ||
.create({ | ||
errorFormatter({ shape }) { | ||
return shape; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createEnv } from "@t3-oss/env-nextjs"; | ||
import { z } from "zod"; | ||
|
||
const env = createEnv({ | ||
server: { | ||
VERCEL_URL: z.string().url(), | ||
}, | ||
client: { | ||
NEXT_PUBLIC_VERCEL_ENV: z.enum(["development", "production"]), | ||
}, | ||
experimental__runtimeEnv: { | ||
NEXT_PUBLIC_VERCEL_ENV: process.env.NEXT_PUBLIC_VERCEL_ENV, | ||
VERCEL_URL: process.env.VERCEL_URL, | ||
}, | ||
}); | ||
|
||
export default env; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { getClientIdToken } from "@/helpers/firebase/auth"; | ||
import { AppRouter } from "@/server/api/routers/root"; | ||
import env from "@/server/env.mjs"; | ||
import { createTRPCProxyClient, httpBatchLink, loggerLink } from "@trpc/client"; | ||
|
||
const getBaseUrl = () => { | ||
if (typeof window !== "undefined") { | ||
return ""; | ||
} | ||
return env.VERCEL_URL; | ||
}; | ||
|
||
export const api = createTRPCProxyClient<AppRouter>({ | ||
links: [ | ||
loggerLink({ | ||
enabled: (opts) => { | ||
if (env.NEXT_PUBLIC_VERCEL_ENV === "development") { | ||
return true; | ||
} | ||
return opts.direction === "down" && opts.result instanceof Error; | ||
}, | ||
}), | ||
httpBatchLink({ | ||
url: `${getBaseUrl()}/api/trpc`, | ||
headers: async () => ({ | ||
authorization: `Bearer ${await getClientIdToken()}`, | ||
}), | ||
}), | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters