pRPC Introduction

AuthPC was renamed to pRPC

What Is pRPC

pRPC is a utility library that combines both

  • Authentication (Auth)
  • Better Solid’S RPC (PC)

Supports

  • pRPC currently supports two Auth Providers: Clerk & AuthJS.
  • pRPC currently supports two Validators: Zod & ValiBot.

pRPC also allows you to throw type-safe errors, redirect the user, modify headers, set cookies and most importantly, you can choose to use either GET (allowing the use of HTTP cache-control headers) or POST.

That means you can create server actions completly type safe, cached, auth/session protected and all in simple function declaration, many might think but wait this is very simple to achieve in other frameworks, what took you so long to create this one, In this doc i’m actually going to explain the behind the scenes of pRPC.

Everything here is type-safe, it also includes middlewares and allowed to be imported to any file thanks to the advance babel plugin.

Usage

In pRPC you can create a better server action that the one you probably have right now, this can be achieved by calling the createCaller method

// server.ts
import { createCaller } from '@solid-mediakit/prpc'
import * as v from 'valibot'

const mySchema = v.object({ name: v.string() })

export const myServerQuery = createCaller(
  mySchema,
  ({ input$, session$, event$ }) => {
    console.log(session$, event$.request.headers.get('user-agent'))
    return `Hey there ${input$.name}`
  },
  {
    method: 'GET',
  },
)

// client.tsx
import { myServerQuery } from './server'
const query = myServerQuery(() => ({ name: 'Demo' }))

pRPC has a lot more features which can’t be fit into one file, please continue to the installation guide