emil
emil
Explore posts from servers
TtRPC
Created by emil on 7/5/2023 in #❓-help
TypeError: client[procedureType] is not a function
oh nice you solved it as well, very nice!
16 replies
TtRPC
Created by emil on 7/5/2023 in #❓-help
TypeError: client[procedureType] is not a function
I used sveltekit so the setup was a bit different and backend was just normal medusa.js node application, the methods are just built like this on the client:
function StorefrontApiAdapter(client: AuthClient): Adapter {
return {
async createUser(user) {
const userSchema = z
.object({
email: z.string(),
emailVerified: z.date().nullable(),
})
.passthrough()

const validatedUser = userSchema.safeParse(user)
if (!validatedUser.success) throw new Error("Not a valid user")

// email magic link does not give a name and image field
const result = await client.authorization.createUser.mutate({
email: validatedUser.data.email,
name: user.name ?? null,
emailVerified: validatedUser.data.emailVerified as string | null, // turns into string on the way to api
image: user.image ?? null,
})
return { ...user, id: result.id }
},

async getUser(id: string): Promise<AdapterUser | null> {
const user = await client.authorization.getUser.query(id)
return transformToAdapterUser(user)
},
//...all the methods used by authjs (did not fit into the msg)
function StorefrontApiAdapter(client: AuthClient): Adapter {
return {
async createUser(user) {
const userSchema = z
.object({
email: z.string(),
emailVerified: z.date().nullable(),
})
.passthrough()

const validatedUser = userSchema.safeParse(user)
if (!validatedUser.success) throw new Error("Not a valid user")

// email magic link does not give a name and image field
const result = await client.authorization.createUser.mutate({
email: validatedUser.data.email,
name: user.name ?? null,
emailVerified: validatedUser.data.emailVerified as string | null, // turns into string on the way to api
image: user.image ?? null,
})
return { ...user, id: result.id }
},

async getUser(id: string): Promise<AdapterUser | null> {
const user = await client.authorization.getUser.query(id)
return transformToAdapterUser(user)
},
//...all the methods used by authjs (did not fit into the msg)
and then that is imported by a the authjs middleware to be used as a custom adapter:
const handleAuth: Handle = SvelteKitAuth(async () => {
return {
secret: config.authSecret,
strategy: "jwt",
trustHost: true,
adapter: StorefrontApiAdapter(config.client),
// ...rest of the object here
const handleAuth: Handle = SvelteKitAuth(async () => {
return {
secret: config.authSecret,
strategy: "jwt",
trustHost: true,
adapter: StorefrontApiAdapter(config.client),
// ...rest of the object here
the config.client is just the tRPC
createTRPCProxyClient
createTRPCProxyClient
16 replies
TtRPC
Created by emil on 7/5/2023 in #❓-help
TypeError: client[procedureType] is not a function
Ooh interesting, yeah they are separate
16 replies
TtRPC
Created by emil on 7/5/2023 in #❓-help
TypeError: client[procedureType] is not a function
The repo is unfortunately private for work, I can check tmrw what the issue was exactly (off the top of my head it was mismatched trpc versions between my front end and backend)
16 replies
TtRPC
Created by emil on 7/5/2023 in #❓-help
TypeError: client[procedureType] is not a function
Oh yeah managed in the end!
16 replies