Skip to content

Is there any docs or open source projects that show how to do authorization ? #1978

Answered by flybayer
allanpope asked this question in Q&A
Discussion options

You must be logged in to vote

Here's how I do it.

Add orgId to session PublicData.

My resolver looks like this:

import { resolver, NotFoundError } from "blitz"
import db, { TestResult as TestResultBase } from "db"
import { ReportData } from "../types"
import * as z from "zod"
import { enforceAdminIfNotCurrentOrganization, setDefaultOrganizationId } from "app/core/utils"

const GetTestResult = z.object({
  id: z.number(),
  organizationId: z.number().optional(),
})

export default resolver.pipe(
  resolver.zod(GetTestResult),
  resolver.authorize(),
  setDefaultOrganizationId,
  enforceAdminIfNotCurrentOrganization,
  async ({ id, organizationId }) => {
    const testResult = await db.testResult.findFirst({
      where: {

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@osirvent
Comment options

@Skn0tt
Comment options

Comment options

You must be logged in to vote
1 reply
@allanpope
Comment options

Answer selected by flybayer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants