Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes in impersonation.mdx #837

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions app/pages/docs/impersonation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default resolver.pipe(

await ctx.session.$create({
userId: user.id,
role: user.role,
role: user.role as Role,
orgId: user.organizationId,
impersonatingFromUserId: ctx.session.userId,
})
Expand Down Expand Up @@ -84,7 +84,7 @@ export default resolver.pipe(resolver.authorize(), async (_, ctx) => {

await ctx.session.$create({
userId: user.id,
role: user.role,
role: user.role as Role,
orgId: user.organizationId,
impersonatingFromUserId: undefined,
})
Expand All @@ -96,7 +96,8 @@ export default resolver.pipe(resolver.authorize(), async (_, ctx) => {
Add a form similar to this in order to switch users.

```tsx
import { useMutation, queryClient } from "@blitzjs/rpc"
// src/auth/components/ImpersonateForm.tsx
import { useMutation } from "@blitzjs/rpc"
import impersonateUser, {
ImpersonateUserInput,
} from "src/auth/mutations/impersonateUser"
Expand Down Expand Up @@ -133,12 +134,18 @@ Lastly, add the following component at the top of your Layout(s).

```tsx
// src/core/components/ImpersonatingUserNotice.tsx
import { invoke, useSession, queryClient } from "@blitzjs/rpc"
import { useSession } from "@blitzjs/auth"
import { invoke } from "@blitzjs/rpc"
import stopImpersonating from "src/auth/mutations/stopImpersonating"

export const ImpersonatingUserNotice = () => {
const session = useSession()
if (!session.impersonatingFromUserId) return null
if (!session.impersonatingFromUserId)
return (
<div className="bg-yellow-400 px-2 py-1 text-center font-semibold">
Currently not impersonating any user
</div>
)

return (
<div className="bg-yellow-400 px-2 py-1 text-center font-semibold">
Expand Down