Brycycle
Brycycle
TTCTheo's Typesafe Cult
Created by Brycycle on 12/16/2023 in #questions
TypeError: GoogleProvider is not a function when running with .ts script using tsx
converting the file to a .tsx produces the same error sadly.
6 replies
TTCTheo's Typesafe Cult
Created by Brycycle on 12/16/2023 in #questions
TypeError: GoogleProvider is not a function when running with .ts script using tsx
I haven't been able to figure out what about the function being defined in next-auth/providers/google causes this error. From my understanding ESM supports default exports, which is what the npm package tsx is able to compile. https://github.com/privatenumber/tsx#readme
6 replies
TTCTheo's Typesafe Cult
Created by Brycycle on 12/16/2023 in #questions
TypeError: GoogleProvider is not a function when running with .ts script using tsx
This, will throw a different error when directly calling getServerAuthSession from a script, but it resolves the TypeError in my actual use case, seen here:
import { createInnerTRPCContext } from "~/server/api/trpc";
import { mockEndUserSession } from "../setup/test-mocks";
import { appRouter } from "~/server/api/root";
const endUserContext = await createInnerTRPCContext({
session: mockEndUserSession,
});

export const endUserCaller = appRouter.createCaller(endUserContext);
import { createInnerTRPCContext } from "~/server/api/trpc";
import { mockEndUserSession } from "../setup/test-mocks";
import { appRouter } from "~/server/api/root";
const endUserContext = await createInnerTRPCContext({
session: mockEndUserSession,
});

export const endUserCaller = appRouter.createCaller(endUserContext);
6 replies
TTCTheo's Typesafe Cult
Created by Brycycle on 12/16/2023 in #questions
TypeError: GoogleProvider is not a function when running with .ts script using tsx
I was able to resolve this issue by writing in the full function definition of GoogleProvider defined in next-auth/providers/google into the ~/server/auth.ts file, like so.
import type { OAuthConfig, OAuthUserConfig } from "next-auth/providers/oauth";
import type { GoogleProfile } from "next-auth/providers/google";

function GoogleProvider<P extends GoogleProfile>(
options: OAuthUserConfig<P>,
): OAuthConfig<P> {
return {
id: "google",
name: "Google",
type: "oauth",
wellKnown: "https://accounts.google.com/.well-known/openid-configuration",
authorization: { params: { scope: "openid email profile" } },
idToken: true,
checks: ["pkce", "state"],
profile(profile) {
return {
id: profile.sub,
name: profile.name,
email: profile.email,
image: profile.picture,
};
},
style: { logo: "/google.svg", bg: "#fff", text: "#000" },
options,
};
}
import type { OAuthConfig, OAuthUserConfig } from "next-auth/providers/oauth";
import type { GoogleProfile } from "next-auth/providers/google";

function GoogleProvider<P extends GoogleProfile>(
options: OAuthUserConfig<P>,
): OAuthConfig<P> {
return {
id: "google",
name: "Google",
type: "oauth",
wellKnown: "https://accounts.google.com/.well-known/openid-configuration",
authorization: { params: { scope: "openid email profile" } },
idToken: true,
checks: ["pkce", "state"],
profile(profile) {
return {
id: profile.sub,
name: profile.name,
email: profile.email,
image: profile.picture,
};
},
style: { logo: "/google.svg", bg: "#fff", text: "#000" },
options,
};
}
6 replies