Has anyone used getSession() with tRPC callers?

I’m curious if anyone has used callers with the server-side validation. Because callers seem to exist outside of the global Next.js request scope, passing headers into getSession() doesn’t seem to be possible. Id like to use all of my data access functions on the server through my tRPC procedures, but my context which contains session info calls headers() outside of the request scope. Any experience/ideas?
13 Replies
Aziz
Aziz3mo ago
Is it just me or is the session from auth.api.getSession() untyped?
bekacru
bekacru3mo ago
it's typed
Aziz
Aziz3mo ago
I think I'm missing something as I have the same code as the example
No description
bekacru
bekacru3mo ago
could you share your tsconfig?
Aziz
Aziz3mo ago
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
bekacru
bekacru3mo ago
your tsconfig looks fine. can you send me your auth config?
Aziz
Aziz3mo ago
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "./db";
import { env } from "./env";

export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "sqlite",
}),
socialProviders: {
apple: {
clientId: env.APPLE_CLIENT_ID,
clientSecret: env.APPLE_CLIENT_SECRET,
appBundleIdentifier: env.APPLE_APP_BUNDLE_ID,
},
google: {
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
},
},
});
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "./db";
import { env } from "./env";

export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "sqlite",
}),
socialProviders: {
apple: {
clientId: env.APPLE_CLIENT_ID,
clientSecret: env.APPLE_CLIENT_SECRET,
appBundleIdentifier: env.APPLE_APP_BUNDLE_ID,
},
google: {
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
},
},
});
bekacru
bekacru3mo ago
In case you're using a monorepo, make sure all ts configs have strict: true set. If not and if you can provide a reproduction of the issue, I'd be happy to take a look.
Aziz
Aziz3mo ago
No worries, I just manually typed it for now just to unblock myself
Json 👺
Json 👺OP3mo ago
Implemented from your docs today. Very helpful.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
bekacru
bekacru3mo ago
clerk still uses headers. as far as I'm aware auth is a server side function. It just since clerk provides nextjs only sdk it doesn't require you to pass the headers, it can call it itself.

Did you find this page helpful?