feat: add clerk auth support with convex (#548)

This commit is contained in:
Aman Varshney
2025-08-29 00:21:08 +05:30
committed by GitHub
parent 8d48ae0359
commit 54bcdf1cbc
153 changed files with 1954 additions and 771 deletions

View File

@@ -1,4 +1,4 @@
{{#if auth}}
{{#if (eq auth "better-auth")}}
import { authClient } from "@/lib/auth-client";
{{/if}}
import { QueryClient } from "@tanstack/react-query";
@@ -12,7 +12,7 @@ const trpcClient = createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: `${process.env.EXPO_PUBLIC_SERVER_URL}/trpc`,
{{#if auth}}
{{#if (eq auth "better-auth")}}
headers() {
const headers = new Map<string, string>();
const cookies = authClient.getCookie();

View File

@@ -1,11 +1,11 @@
{{#if (eq backend 'next')}}
import type { NextRequest } from "next/server";
{{#if auth}}
{{#if (eq auth "better-auth")}}
import { auth } from "./auth";
{{/if}}
export async function createContext(req: NextRequest) {
{{#if auth}}
{{#if (eq auth "better-auth")}}
const session = await auth.api.getSession({
headers: req.headers,
});
@@ -22,7 +22,7 @@ export async function createContext(req: NextRequest) {
{{else if (eq backend 'hono')}}
import type { Context as HonoContext } from "hono";
{{#if auth}}
{{#if (eq auth "better-auth")}}
import { auth } from "./auth";
{{/if}}
@@ -31,7 +31,7 @@ export type CreateContextOptions = {
};
export async function createContext({ context }: CreateContextOptions) {
{{#if auth}}
{{#if (eq auth "better-auth")}}
const session = await auth.api.getSession({
headers: context.req.raw.headers,
});
@@ -48,7 +48,7 @@ export async function createContext({ context }: CreateContextOptions) {
{{else if (eq backend 'elysia')}}
import type { Context as ElysiaContext } from "elysia";
{{#if auth}}
{{#if (eq auth "better-auth")}}
import { auth } from "./auth";
{{/if}}
@@ -57,7 +57,7 @@ export type CreateContextOptions = {
};
export async function createContext({ context }: CreateContextOptions) {
{{#if auth}}
{{#if (eq auth "better-auth")}}
const session = await auth.api.getSession({
headers: context.request.headers,
});
@@ -74,13 +74,13 @@ export async function createContext({ context }: CreateContextOptions) {
{{else if (eq backend 'express')}}
import type { CreateExpressContextOptions } from "@trpc/server/adapters/express";
{{#if auth}}
{{#if (eq auth "better-auth")}}
import { fromNodeHeaders } from "better-auth/node";
import { auth } from "./auth";
{{/if}}
export async function createContext(opts: CreateExpressContextOptions) {
{{#if auth}}
{{#if (eq auth "better-auth")}}
const session = await auth.api.getSession({
headers: fromNodeHeaders(opts.req.headers),
});
@@ -97,13 +97,13 @@ export async function createContext(opts: CreateExpressContextOptions) {
{{else if (eq backend 'fastify')}}
import type { CreateFastifyContextOptions } from "@trpc/server/adapters/fastify";
{{#if auth}}
{{#if (eq auth "better-auth")}}
import { fromNodeHeaders } from "better-auth/node";
import { auth } from "./auth";
{{/if}}
export async function createContext({ req, res }: CreateFastifyContextOptions) {
{{#if auth}}
{{#if (eq auth "better-auth")}}
const session = await auth.api.getSession({
headers: fromNodeHeaders(req.headers),
});

View File

@@ -7,7 +7,7 @@ export const router = t.router;
export const publicProcedure = t.procedure;
{{#if auth}}
{{#if (eq auth "better-auth")}}
export const protectedProcedure = t.procedure.use(({ ctx, next }) => {
if (!ctx.session) {
throw new TRPCError({

View File

@@ -28,7 +28,7 @@ const trpcClient = createTRPCClient<AppRouter>({
{{else}}
url: `${import.meta.env.VITE_SERVER_URL}/trpc`,
{{/if}}
{{#if auth}}
{{#if (eq auth "better-auth")}}
fetch(url, options) {
return fetch(url, {
...options,
@@ -78,7 +78,7 @@ export const trpcClient = createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: `${import.meta.env.VITE_SERVER_URL}/trpc`,
{{#if auth}}
{{#if (eq auth "better-auth")}}
fetch(url, options) {
return fetch(url, {
...options,