1.3.0 • Published 7 months ago
@universal-packages/trpc-authentication v1.3.0
tRPC Authentication
universal-authentication implementation on top of trpc
Install
npm install @universal-packages/trpc-authentication
Global methods
initialize(options: Object)
Initialize the authentication api configuration for the authentication trpc routers.
import { initialize } from '@universal-packages/trpc-authentication'
await initialize({ secret: 'my-secret' })
Options
initialize
takes the same options as Authentication
.
Router creators
createAuthenticationRouter(trpc: TRPCInstance)
Create a trpc router with the authentication methods.
import { initTRPC } from '@trpc/server'
import { createAuthenticationRouter, initialize } from '@universal-packages/trpc-authentication'
await initialize({ secret: 'my-secret' })
export const trpc = initTRPC.create()
export const appRouter = trpc.router({
authentication: createAuthenticationRouter(trpc)
})
createDefaultAuthenticationModuleRouter(trpc: TRPCInstance)
Create a trpc router with the default authentication module methods. You usually want to combine the base router with other modules.
import { initTRPC } from '@trpc/server'
import { createAuthenticationRouter, createDefaultAuthenticationModuleRouter, initialize } from '@universal-packages/trpc-authentication'
export const trpc = initTRPC.create()
export const appRouter = trpc.router({
authentication: trpc.mergeRouters(createAuthenticationRouter(trpc), createDefaultAuthenticationModuleRouter(trpc))
})
Typescript
This library is developed in TypeScript and shipped fully typed.
Contributing
The development of this library happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving this library.