@@ -11,6 +11,7 @@ import { Pagination } from './_components/pagination';
11
11
import { Suspense } from 'react' ;
12
12
import type { RepoData , RepoItem , RepoResponse } from '@/types' ;
13
13
import type { Metadata } from 'next' ;
14
+ import { auth } from '@/auth' ;
14
15
15
16
interface ReposPageProps {
16
17
params : { language : string } ;
@@ -72,6 +73,8 @@ async function getRepos(
72
73
language : string ,
73
74
searchParams : ReposPageProps [ 'searchParams' ]
74
75
) : Promise < RepoResponse > {
76
+ const client = getXataClient ( ) ;
77
+ const session = await auth ( ) ;
75
78
const {
76
79
p : page = '1' ,
77
80
s : sort = '' ,
@@ -103,9 +106,22 @@ async function getRepos(
103
106
const headers : HeadersInit = {
104
107
Accept : 'application/vnd.github.mercy-preview+json'
105
108
} ;
106
-
107
- if ( env . AUTH_GITHUB_TOKEN )
109
+ const userId = session ?. user ?. id ;
110
+
111
+ if ( userId ) {
112
+ const account = await client . db . nextauth_accounts
113
+ . select ( [ 'access_token' ] )
114
+ . filter ( { 'user.id' : userId } )
115
+ . getFirst ( ) ;
116
+
117
+ if ( account && account . access_token ) {
118
+ headers . Authorization = `Bearer ${ account . access_token } ` ;
119
+ } else if ( env . AUTH_GITHUB_TOKEN ) {
120
+ headers . Authorization = `Bearer ${ env . AUTH_GITHUB_TOKEN } ` ;
121
+ }
122
+ } else if ( env . AUTH_GITHUB_TOKEN ) {
108
123
headers . Authorization = `Bearer ${ env . AUTH_GITHUB_TOKEN } ` ;
124
+ }
109
125
110
126
const res = await fetch ( apiUrl , { headers } ) ;
111
127
if ( ! res . ok ) notFound ( ) ;
0 commit comments