Skip to content

Commit

Permalink
wip: Use trpc context to allow impersonating endUser
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyxiao committed Oct 25, 2023
1 parent e3ae7ad commit 3c87da7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 14 additions & 1 deletion apps/web/app/(admin)/(authenticated)/magic-link/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
'use client'

import React from 'react'

import {adminRouterSchema} from '@usevenice/engine-backend/router/adminRouter'
import {_trpcReact} from '@usevenice/engine-frontend'
import {SchemaForm, useToast} from '@usevenice/ui'
import {Input, Label, SchemaForm, useToast} from '@usevenice/ui'

import {copyToClipboard} from '@/lib-client/copyToClipboard'

export default function MagicLinkPage() {
const {toast} = useToast()

const [endUserId, setEndUserId] = React.useState('')

const createMagicLink = _trpcReact.adminCreateMagicLink.useMutation({
trpc: {context: {impersonatedEndUserId: endUserId}},
meta: {},
onError: (err) => {
toast({
title: 'Error creating magic link',
Expand All @@ -22,6 +28,13 @@ export default function MagicLinkPage() {
return (
<div className="p-6">
<h2 className="mb-4 text-2xl font-semibold tracking-tight">Magic link</h2>
<Label htmlFor="endUserId">End user ID</Label>
<Input
id="endUserId"
value={endUserId}
onChange={(e) => setEndUserId(e.target.value)}
/>
<hr />
<SchemaForm
schema={adminRouterSchema.adminCreateMagicLink.input}
loading={createMagicLink.isLoading}
Expand Down
6 changes: 6 additions & 0 deletions packages/engine-frontend/TRPCProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export function TRPCProvider({
// createTRPCProxyClient<FlatRouter>({
_trpcReact.createClient({
links: [
() =>
({op, next}) => {
// TODO: Implement impersonation here based on context
console.log('op.context', op.context)
return next(op)
},
(debug ? httpLink : httpBatchLink)({
url: apiUrl ?? '/api/trpc',
headers: () => ({
Expand Down

0 comments on commit 3c87da7

Please sign in to comment.