@@ -112,23 +112,24 @@ export async function requireUser(request: Request) {
112
112
This is a great way to make nice utilities that make the regular application
113
113
code much easier to write and read:
114
114
115
- ``` tsx filename=app/routes/sandwiches.$sandwichId.tsx add=8,17 remove=9-12 ,18-21
115
+ ``` tsx filename=app/routes/sandwiches.$sandwichId.tsx add=8,17 remove=9-13 ,18-22
116
116
import { json , type DataFunctionArgs , type MetaFunction } from ' @remix-run/node'
117
117
import { invariantResponse , useIsSubmitting } from ' #app/utils/misc.tsx'
118
118
import { getUser } from ' #app/utils/auth.server'
119
119
import { requireUser } from ' #app/utils/auth.server'
120
120
import { getSandwich } from ' #app/utils/sandwiches.server'
121
121
122
122
export async function loader({ request , params }: DataFunctionArgs ) {
123
+ const user = await requireUser (request )
123
124
const user = await getUser (request )
124
125
if (! user ) {
125
126
// this response will be handled by our error boundary
126
127
throw new Response (' Unauthorized' , { status: 401 })
127
128
}
128
- const user = await requireUser (request )
129
129
// this invariant with throw an error which our error boundary will handle as well
130
130
invariantResponse (params .sandwichId , ' sandwichId is required' )
131
131
132
+ const sandwich = await requireSandwich (params .sandwichId )
132
133
const sandwich = await getSandwich (params .sandwichId )
133
134
if (! sandwich ) {
134
135
// this response will be handled by our error boundary
0 commit comments