blitz-js / blitz

⚡️ The Missing Fullstack Toolkit for Next.js
https://Blitzjs.com
MIT License
13.63k stars 798 forks source link

feat: Blitz RPC endpoint to the app directory #4341

Closed siddhsuresh closed 3 months ago

siddhsuresh commented 4 months ago

What are the changes and their implications?

Usage:

// app/api/rpc/[[...blitz]]/route.ts
import {rpcAppHandler} from "@blitzjs/rpc"
import {withBlitzAuth} from "app/blitz-server"

export const {GET, POST, HEAD} = withBlitzAuth(rpcAppHandler())

If using only auth and not rpc in the route.ts files

//app/api/logout/route.ts
export const {POST} = withBlitzAuth({
  POST: async (_request, _params, ctx) => {
    const session = ctx.session
    await session.$revoke()

    return new Response(
      JSON.stringify({
        userId: session.userId,
      }),
      {status: 200},
    )
  },
})

Feature Checklist

changeset-bot[bot] commented 4 months ago

🦋 Changeset detected

Latest commit: 14b9e0f599bc173c625eb4a5ecc2525e5599cb7c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages | Name | Type | | ------------------ | ----- | | blitz | Minor | | @blitzjs/auth | Major | | @blitzjs/next | Major | | @blitzjs/rpc | Major | | @blitzjs/generator | Major | | next-blitz-auth | Patch | | @blitzjs/codemod | Major | | @blitzjs/config | Major |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

siddhsuresh commented 4 months ago

!preview app-dir-blitz-rpc

github-actions[bot] commented 4 months ago

Snapshot Release app-dir-blitz-rpc

siddhsuresh commented 4 months ago

!preview app-dir-blitz-rpc

github-actions[bot] commented 4 months ago

Snapshot Release app-dir-blitz-rpc

siddhsuresh commented 4 months ago

!preview app-dir-blitz-rpc

github-actions[bot] commented 4 months ago

Snapshot Release app-dir-blitz-rpc

siddhsuresh commented 3 months ago

!preview app-dir-blitz-rpc

siddhsuresh commented 3 months ago

!preview app-dir-blitz-rpc

siddhsuresh commented 3 months ago

!preview app-dir-blitz-rpc

siddhsuresh commented 3 months ago

!preview app-dir-blitz-rpc

github-actions[bot] commented 3 months ago

Snapshot Release app-dir-blitz-rpc