File tree Expand file tree Collapse file tree 2 files changed +24
-8
lines changed
app/(protected)/subscriptions Expand file tree Collapse file tree 2 files changed +24
-8
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import {
2323 TableRow ,
2424} from '@/components/ui/table'
2525import { getListSubs } from '@/lib/api/subscription'
26+ import { Verify } from '@/lib/firebase/firebase'
2627import Link from 'next/link'
2728
2829export default async function Subscriptions ( {
@@ -38,14 +39,24 @@ export default async function Subscriptions({
3839 const skip = Number ( sp ?. skip ?? 0 )
3940 const limit = Number ( sp ?. limit ?? 20 )
4041 const library_id = sp ?. library_id
41- const res = await getListSubs ( {
42- sort_by : 'created_at' ,
43- sort_in : 'desc' ,
44- limit : limit ,
45- skip : skip ,
46- ...( library_id ? { library_id } : { } ) ,
42+
43+ const headers = await Verify ( {
44+ from : '/borrows' ,
4745 } )
4846
47+ const res = await getListSubs (
48+ {
49+ sort_by : 'created_at' ,
50+ sort_in : 'desc' ,
51+ limit : limit ,
52+ skip : skip ,
53+ ...( library_id ? { library_id } : { } ) ,
54+ } ,
55+ {
56+ headers,
57+ }
58+ )
59+
4960 if ( 'error' in res ) {
5061 console . log ( res )
5162 return < div > { JSON . stringify ( res . message ) } </ div >
Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ type GetListSubsQuery = QueryParams<
1313type GetListSubsResponse = Promise < ResList < Subscription > >
1414
1515export const getListSubs = async (
16- query : GetListSubsQuery
16+ query : GetListSubsQuery ,
17+ init ?: RequestInit
1718) : GetListSubsResponse => {
1819 const url = new URL ( SUBSCRIPTIONS_URL )
1920 Object . entries ( query ) . forEach ( ( [ key , value ] ) => {
@@ -22,7 +23,11 @@ export const getListSubs = async (
2223 }
2324 } )
2425 try {
25- const response = await fetch ( url . toString ( ) )
26+ const response = await fetch ( url . toString ( ) , init )
27+ if ( ! response . ok ) {
28+ const e = await response . json ( )
29+ throw e
30+ }
2631 return response . json ( )
2732 } catch ( error ) {
2833 return {
You can’t perform that action at this time.
0 commit comments