Skip to content

Commit 568a5ad

Browse files
committed
feat(next): support nextjs 15.1
1 parent 9306271 commit 568a5ad

4 files changed

Lines changed: 146 additions & 20 deletions

File tree

packages/next/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
},
5151
"peerDependencies": {
5252
"@orpc/server": "workspace:*",
53-
"next": ">=15.0.0",
53+
"next": ">=15.1.0",
5454
"react": ">=18.3.0"
5555
},
5656
"dependencies": {

packages/next/src/action-form.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE, CreateProcedureCallerOptions } from '@orpc/server'
22
import { createProcedureCaller, loadProcedure, ORPCError } from '@orpc/server'
33
import { OpenAPIDeserializer } from '@orpc/transformer'
4-
import { notFound } from 'next/navigation'
4+
import { forbidden, notFound, unauthorized } from 'next/navigation'
55

66
export type FormAction = (input: FormData) => Promise<void>
77

@@ -21,8 +21,18 @@ export function createFormAction<T extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE>(o
2121
await caller(deserializedInput)
2222
}
2323
catch (e) {
24-
if (e instanceof ORPCError && e.code === 'NOT_FOUND') {
25-
notFound()
24+
if (e instanceof ORPCError) {
25+
if (e.code === 'NOT_FOUND') {
26+
notFound()
27+
}
28+
29+
if (e.code === 'FORBIDDEN') {
30+
forbidden()
31+
}
32+
33+
if (e.code === 'UNAUTHORIZED') {
34+
unauthorized()
35+
}
2636
}
2737

2838
throw e

packages/next/src/action-safe.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import type { SchemaInput, SchemaOutput } from '@orpc/contract'
22
import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE, CreateProcedureCallerOptions, Lazy, Procedure, WELL_ORPC_ERROR_JSON } from '@orpc/server'
33
import { createProcedureCaller, ORPCError } from '@orpc/server'
4-
import { isNotFoundError } from 'next/dist/client/components/not-found'
5-
import { isRedirectError } from 'next/dist/client/components/redirect'
64

75
export type SafeAction<T extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE> = T extends
86
| Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput>
@@ -26,10 +24,6 @@ export function createSafeAction<T extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE>(o
2624
return [output as any, undefined, 'success']
2725
}
2826
catch (e) {
29-
if (isRedirectError(e)) {
30-
throw e
31-
}
32-
3327
const error = convertToORPCError(e)
3428

3529
return [undefined, error.toJSON(), 'error']
@@ -44,14 +38,6 @@ function convertToORPCError(e: unknown): ORPCError<any, any> {
4438
return e
4539
}
4640

47-
if (isNotFoundError(e)) {
48-
return new ORPCError({
49-
code: 'NOT_FOUND',
50-
message: 'Not found',
51-
cause: e,
52-
})
53-
}
54-
5541
return new ORPCError({
5642
code: 'INTERNAL_SERVER_ERROR',
5743
message: 'Internal server error',

pnpm-lock.yaml

Lines changed: 132 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)