mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
feat: add clerk auth support with convex (#548)
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"devDependencies": {
|
||||
"@types/node": "^24.3.0",
|
||||
"typescript": "^5.9.2"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -14,7 +14,7 @@ import { RPCHandler } from "@orpc/server/fetch";
|
||||
import { appRouter } from "./routers";
|
||||
import { createContext } from "./lib/context";
|
||||
{{/if}}
|
||||
{{#if auth}}
|
||||
{{#if (eq auth "better-auth")}}
|
||||
import { auth } from "./lib/auth";
|
||||
{{/if}}
|
||||
|
||||
@@ -31,13 +31,13 @@ const app = new Elysia()
|
||||
cors({
|
||||
origin: process.env.CORS_ORIGIN || "",
|
||||
methods: ["GET", "POST", "OPTIONS"],
|
||||
{{#if auth}}
|
||||
{{#if (eq auth "better-auth")}}
|
||||
allowedHeaders: ["Content-Type", "Authorization"],
|
||||
credentials: true,
|
||||
{{/if}}
|
||||
}),
|
||||
)
|
||||
{{#if auth}}
|
||||
{{#if (eq auth "better-auth")}}
|
||||
.all("/api/auth/*", async (context) => {
|
||||
const { request } = context;
|
||||
if (["POST", "GET"].includes(request.method)) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { appRouter } from "./routers/index";
|
||||
{{#if (eq api "orpc")}}
|
||||
import { RPCHandler } from "@orpc/server/node";
|
||||
import { appRouter } from "./routers";
|
||||
{{#if auth}}
|
||||
{{#if (eq auth "better-auth")}}
|
||||
import { createContext } from "./lib/context";
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
@@ -17,7 +17,7 @@ import express from "express";
|
||||
import { streamText, type UIMessage, convertToModelMessages } from "ai";
|
||||
import { google } from "@ai-sdk/google";
|
||||
{{/if}}
|
||||
{{#if auth}}
|
||||
{{#if (eq auth "better-auth")}}
|
||||
import { auth } from "./lib/auth";
|
||||
import { toNodeHandler } from "better-auth/node";
|
||||
{{/if}}
|
||||
@@ -28,14 +28,14 @@ app.use(
|
||||
cors({
|
||||
origin: process.env.CORS_ORIGIN || "",
|
||||
methods: ["GET", "POST", "OPTIONS"],
|
||||
{{#if auth}}
|
||||
{{#if (eq auth "better-auth")}}
|
||||
allowedHeaders: ["Content-Type", "Authorization"],
|
||||
credentials: true,
|
||||
{{/if}}
|
||||
})
|
||||
);
|
||||
|
||||
{{#if auth}}
|
||||
{{#if (eq auth "better-auth")}}
|
||||
app.all("/api/auth{/*path}", toNodeHandler(auth));
|
||||
{{/if}}
|
||||
|
||||
@@ -54,7 +54,7 @@ const handler = new RPCHandler(appRouter);
|
||||
app.use("/rpc{*path}", async (req, res, next) => {
|
||||
const { matched } = await handler.handle(req, res, {
|
||||
prefix: "/rpc",
|
||||
{{#if auth}}
|
||||
{{#if (eq auth "better-auth")}}
|
||||
context: await createContext({ req }),
|
||||
{{else}}
|
||||
context: {},
|
||||
@@ -85,4 +85,4 @@ app.get("/", (_req, res) => {
|
||||
const port = process.env.PORT || 3000;
|
||||
app.listen(port, () => {
|
||||
console.log(`Server is running on port ${port}`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,7 +13,7 @@ import { RPCHandler } from "@orpc/server/node";
|
||||
import { CORSPlugin } from "@orpc/server/plugins";
|
||||
import { appRouter } from "./routers/index";
|
||||
import { createServer } from "node:http";
|
||||
{{#if auth}}
|
||||
{{#if (eq auth "better-auth")}}
|
||||
import { createContext } from "./lib/context";
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
@@ -23,7 +23,7 @@ import { streamText, type UIMessage, convertToModelMessages } from "ai";
|
||||
import { google } from "@ai-sdk/google";
|
||||
{{/if}}
|
||||
|
||||
{{#if auth}}
|
||||
{{#if (eq auth "better-auth")}}
|
||||
import { auth } from "./lib/auth";
|
||||
{{/if}}
|
||||
|
||||
@@ -77,7 +77,7 @@ const fastify = Fastify({
|
||||
|
||||
fastify.register(fastifyCors, baseCorsConfig);
|
||||
|
||||
{{#if auth}}
|
||||
{{#if (eq auth "better-auth")}}
|
||||
fastify.route({
|
||||
method: ["GET", "POST"],
|
||||
url: "/api/auth/*",
|
||||
@@ -149,4 +149,4 @@ fastify.listen({ port: 3000 }, (err) => {
|
||||
process.exit(1);
|
||||
}
|
||||
console.log("Server running on port 3000");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@ import { trpcServer } from "@hono/trpc-server";
|
||||
import { createContext } from "./lib/context";
|
||||
import { appRouter } from "./routers/index";
|
||||
{{/if}}
|
||||
{{#if auth}}
|
||||
{{#if (eq auth "better-auth")}}
|
||||
import { auth } from "./lib/auth";
|
||||
{{/if}}
|
||||
import { Hono } from "hono";
|
||||
@@ -42,14 +42,14 @@ app.use(
|
||||
origin: env.CORS_ORIGIN || "",
|
||||
{{/if}}
|
||||
allowMethods: ["GET", "POST", "OPTIONS"],
|
||||
{{#if auth}}
|
||||
{{#if (eq auth "better-auth")}}
|
||||
allowHeaders: ["Content-Type", "Authorization"],
|
||||
credentials: true,
|
||||
{{/if}}
|
||||
})
|
||||
);
|
||||
|
||||
{{#if auth}}
|
||||
{{#if (eq auth "better-auth")}}
|
||||
app.on(["POST", "GET"], "/api/auth/**", (c) => auth.handler(c.req.raw));
|
||||
{{/if}}
|
||||
|
||||
@@ -133,4 +133,4 @@ export default app;
|
||||
{{#if (eq runtime "workers")}}
|
||||
export default app;
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{{#if (eq api "orpc")}}
|
||||
import { {{#if auth}}protectedProcedure, {{/if}}publicProcedure } from "../lib/orpc";
|
||||
import { {{#if (eq auth "better-auth")}}protectedProcedure, {{/if}}publicProcedure } from "../lib/orpc";
|
||||
import type { RouterClient } from "@orpc/server";
|
||||
{{#if (includes examples "todo")}}
|
||||
import { todoRouter } from "./todo";
|
||||
@@ -9,7 +9,7 @@ export const appRouter = {
|
||||
healthCheck: publicProcedure.handler(() => {
|
||||
return "OK";
|
||||
}),
|
||||
{{#if auth}}
|
||||
{{#if (eq auth "better-auth")}}
|
||||
privateData: protectedProcedure.handler(({ context }) => {
|
||||
return {
|
||||
message: "This is private",
|
||||
@@ -25,7 +25,7 @@ export type AppRouter = typeof appRouter;
|
||||
export type AppRouterClient = RouterClient<typeof appRouter>;
|
||||
{{else if (eq api "trpc")}}
|
||||
import {
|
||||
{{#if auth}}protectedProcedure, {{/if}}publicProcedure,
|
||||
{{#if (eq auth "better-auth")}}protectedProcedure, {{/if}}publicProcedure,
|
||||
router,
|
||||
} from "../lib/trpc";
|
||||
{{#if (includes examples "todo")}}
|
||||
@@ -36,7 +36,7 @@ export const appRouter = router({
|
||||
healthCheck: publicProcedure.query(() => {
|
||||
return "OK";
|
||||
}),
|
||||
{{#if auth}}
|
||||
{{#if (eq auth "better-auth")}}
|
||||
privateData: protectedProcedure.query(({ ctx }) => {
|
||||
return {
|
||||
message: "This is private",
|
||||
|
||||
Reference in New Issue
Block a user