Property 'callbackOAuth' does not exist on type 'InferAPI'

Hey, I use React-Router v7 framework mode. I have a custom endpoint, to validate OAuth Callbacks. Typescript says there is no such method. All I want, is to get Headers and do some modifications. Tried many things, but nothing. Bellow is working code with some "hacks". Session cookie is set here. And all works. But it does not look good...
import { href, redirect } from 'react-router';
import { type callbackOAuth } from 'better-auth/api';

import { APIError, auth } from '~/services/auth.server';
import type { Route } from './+types/$providerId.callback';

export const loader = async ({ request, params }: Route.LoaderArgs) => {
try {
const url = new URL(request.url);
const { state, code, device_id, error, user, error_description } = Object.fromEntries(url.searchParams);

await ((auth.api as any).callbackOAuth as typeof callbackOAuth)({
request,
headers: request.headers,
returnHeaders: true,
method: 'GET',
query: {
state,
code,
device_id,
error,
user,
error_description,
},
params: {
id: params.providerId,
},
});
} catch (error) {
if (error instanceof APIError) {
if (error.headers) {
return redirect(href('/auth/login'), { headers: error.headers });
}
}
return redirect(href('/auth/login'));
}
};
import { href, redirect } from 'react-router';
import { type callbackOAuth } from 'better-auth/api';

import { APIError, auth } from '~/services/auth.server';
import type { Route } from './+types/$providerId.callback';

export const loader = async ({ request, params }: Route.LoaderArgs) => {
try {
const url = new URL(request.url);
const { state, code, device_id, error, user, error_description } = Object.fromEntries(url.searchParams);

await ((auth.api as any).callbackOAuth as typeof callbackOAuth)({
request,
headers: request.headers,
returnHeaders: true,
method: 'GET',
query: {
state,
code,
device_id,
error,
user,
error_description,
},
params: {
id: params.providerId,
},
});
} catch (error) {
if (error instanceof APIError) {
if (error.headers) {
return redirect(href('/auth/login'), { headers: error.headers });
}
}
return redirect(href('/auth/login'));
}
};
No description
1 Reply
Eimis
EimisOP3w ago
my config:
export const auth = betterAuth({
appName: env.APP_NAME,
baseURL: env.BASE_URL,
secret: env.BETTER_AUTH_SECRET,
basePath: env.BETTER_AUTH_BASE_PATH,
database: drizzleAdapter(mainDb, { provider: 'sqlite' }),
advanced: { cookiePrefix: 'fs' },
emailAndPassword: {
enabled: true,
sendResetPassword: ({ user, token }) => {
console.log({ user, url: `${env.BASE_URL}/auth/reset/${token}` });
return Promise.resolve();
},
},
socialProviders: {
google: {
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
redirectURI: `${env.BASE_URL}${href('/auth/:providerId/callback', { providerId: 'google' })}`,
},
},
plugins: [
admin(),
organization({
allowUserToCreateOrganization: true,
teams: { enabled: true },
}),
],
});
export const auth = betterAuth({
appName: env.APP_NAME,
baseURL: env.BASE_URL,
secret: env.BETTER_AUTH_SECRET,
basePath: env.BETTER_AUTH_BASE_PATH,
database: drizzleAdapter(mainDb, { provider: 'sqlite' }),
advanced: { cookiePrefix: 'fs' },
emailAndPassword: {
enabled: true,
sendResetPassword: ({ user, token }) => {
console.log({ user, url: `${env.BASE_URL}/auth/reset/${token}` });
return Promise.resolve();
},
},
socialProviders: {
google: {
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
redirectURI: `${env.BASE_URL}${href('/auth/:providerId/callback', { providerId: 'google' })}`,
},
},
plugins: [
admin(),
organization({
allowUserToCreateOrganization: true,
teams: { enabled: true },
}),
],
});

Did you find this page helpful?