File tree 1 file changed +8
-4
lines changed
1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 1
1
import { cookies } from 'next/headers'
2
- import { redirect } from 'next/navigation'
2
+ import { notFound , redirect } from 'next/navigation'
3
3
import type { NoteWrappedWithLikedPayload } from '@mx-space/api-client'
4
4
5
5
import { getAuthFromCookie } from '~/lib/attach-fetch'
@@ -9,7 +9,7 @@ import { definePrerenderPage } from '~/lib/request.server'
9
9
10
10
export default definePrerenderPage ( ) ( {
11
11
async fetcher ( ) {
12
- const { data } =
12
+ const latest =
13
13
await apiClient . note . proxy . latest . get < NoteWrappedWithLikedPayload > ( {
14
14
params : {
15
15
token : getAuthFromCookie ( )
@@ -18,9 +18,13 @@ export default definePrerenderPage()({
18
18
} ,
19
19
} )
20
20
21
- return data
21
+ return latest ?. data
22
22
} ,
23
- Component : ( { data : { nid, hide } } ) => {
23
+ Component : ( { data : nullableData } ) => {
24
+ if ( ! nullableData ) {
25
+ notFound ( )
26
+ }
27
+ const { nid, hide } = nullableData
24
28
const jwt = cookies ( ) . get ( AuthKeyNames [ 0 ] ) ?. value
25
29
if ( hide ) {
26
30
return redirect ( `/notes/${ nid } ?token=${ jwt } ` )
You can’t perform that action at this time.
0 commit comments