© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•6mo ago•
6 replies
Vikram

Proper way to the authorize the user in an Inngest function?

Hey there, looking for some help wrapping my head around getting the user session in an Inngest function. I have my project updated to use the newer
getClaims
getClaims
method also. In the following code the
getClaims
getClaims
data is empty which is expected in this scope. What would be the proper way to get the session validated in this scope to perform CRUD operations on the tables?

Inngest function
export default inngest.createFunction(
  { id: 'process' },
  { event: 'process' },
  async ({ event, step }) => {
    const { fileData, fileType } = event.data

    if (!fileData || !fileType) {
      throw new Error('No fileData or fileType provided in event payload')
    }

    const supabase = await createClient()
    const { data: user } = await supabase.auth.getClaims()

    if (!user?.claims) {
      throw new Error('No user claims provided in event payload') <<<<< FAILS (EXPECTED)
    }

    const userId = user.claims.sub

...rest
export default inngest.createFunction(
  { id: 'process' },
  { event: 'process' },
  async ({ event, step }) => {
    const { fileData, fileType } = event.data

    if (!fileData || !fileType) {
      throw new Error('No fileData or fileType provided in event payload')
    }

    const supabase = await createClient()
    const { data: user } = await supabase.auth.getClaims()

    if (!user?.claims) {
      throw new Error('No user claims provided in event payload') <<<<< FAILS (EXPECTED)
    }

    const userId = user.claims.sub

...rest


API route that triggers the Inngest function
export async function POST(req: Request) {
  try {
    const supabase = await createClient()

    const { data, error: authError } = await supabase.auth.getClaims()

    if (authError || !data?.claims) {
      return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
    }

    const body = await req.json()
    const { fileData, fileType } = body

    if (!fileData || !fileType) {
      return NextResponse.json({ error: 'fileData and fileType are required' }, { status: 400 })
    }

    await inngest.send({
      name: 'process',
      data: {
        fileData,
        fileType,
      },
    })

    return NextResponse.json({
      success: true,
      message: 'Processing started',
    })
  } catch (error) {
    return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
  }
}
export async function POST(req: Request) {
  try {
    const supabase = await createClient()

    const { data, error: authError } = await supabase.auth.getClaims()

    if (authError || !data?.claims) {
      return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
    }

    const body = await req.json()
    const { fileData, fileType } = body

    if (!fileData || !fileType) {
      return NextResponse.json({ error: 'fileData and fileType are required' }, { status: 400 })
    }

    await inngest.send({
      name: 'process',
      data: {
        fileData,
        fileType,
      },
    })

    return NextResponse.json({
      success: true,
      message: 'Processing started',
    })
  } catch (error) {
    return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
  }
}
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Get auth user in function
SupabaseSSupabase / help-and-questions
4y ago
Proper Way To Call Edge From Trigger
SupabaseSSupabase / help-and-questions
14mo ago
Proper way to createUrls from multiple rows
SupabaseSSupabase / help-and-questions
3y ago
increment function, need user uuid in edge function.
SupabaseSSupabase / help-and-questions
3y ago