1- import { randomBytes } from 'node:crypto' ;
2-
3- import { encrypt } from '../utils/encryption.js' ;
4-
51import type { FastifyInstance , FastifyRequest , FastifyReply } from 'fastify' ;
2+ import { randomBytes } from 'crypto' ;
3+ import { encrypt } from '../utils/encryption.js' ;
64
75const GITHUB_AUTH_URL = 'https://github.com/login/oauth/authorize' ;
86const GITHUB_TOKEN_URL = 'https://github.com/login/oauth/access_token' ;
@@ -24,17 +22,17 @@ interface ParsedOAuthState {
2422 nonce : string ;
2523}
2624
27- export async function connectRoutes ( app : FastifyInstance ) {
25+ export async function connectRoutes ( app : FastifyInstance ) : Promise < void > {
2826 // ─── Status ───
2927
3028 app . get ( '/status' , {
3129 preHandler : [ async ( request , reply ) => {
3230 const server = request . server as any ;
3331 if ( typeof server ?. authenticate === 'function' ) { await server . authenticate ( request , reply ) ; return }
3432 if ( typeof ( app as any ) . authenticate === 'function' ) { await ( app as any ) . authenticate ( request , reply ) ; return }
35- try { await request . jwtVerify ( ) } catch ( e ) { reply . status ( 401 ) . send ( { error : 'Unauthorized' } ) }
33+ try { await request . jwtVerify ( ) } catch { reply . status ( 401 ) . send ( { error : 'Unauthorized' } ) }
3634 } ] ,
37- } , async ( request : FastifyRequest , reply : FastifyReply ) => {
35+ } , async ( request : FastifyRequest , _reply : FastifyReply ) => {
3836 const userId = ( request . user as any ) . id ;
3937
4038 const tokens = await app . prisma . oAuthToken . findMany ( {
@@ -52,7 +50,7 @@ export async function connectRoutes(app: FastifyInstance) {
5250 const server = request . server as any ;
5351 if ( typeof server ?. authenticate === 'function' ) { await server . authenticate ( request , reply ) ; return }
5452 if ( typeof ( app as any ) . authenticate === 'function' ) { await ( app as any ) . authenticate ( request , reply ) ; return }
55- try { await request . jwtVerify ( ) } catch ( e ) { reply . status ( 401 ) . send ( { error : 'Unauthorized' } ) }
53+ try { await request . jwtVerify ( ) } catch { reply . status ( 401 ) . send ( { error : 'Unauthorized' } ) }
5654 } ] ,
5755 } , async ( request : FastifyRequest , reply : FastifyReply ) => {
5856 const userId = ( request . user as any ) . id ;
@@ -104,7 +102,7 @@ export async function connectRoutes(app: FastifyInstance) {
104102 }
105103
106104 // Consume the nonce -- one-time use only (if redis configured)
107- if ( app . redis ) { await app . redis . del ( `oauth:nonce:${ decodedState . nonce } ` ) ; }
105+ if ( app . redis ) await app . redis . del ( `oauth:nonce:${ decodedState . nonce } ` ) ;
108106
109107 const userId = decodedState . userId ;
110108
@@ -177,7 +175,7 @@ export async function connectRoutes(app: FastifyInstance) {
177175 const server = request . server as any ;
178176 if ( typeof server ?. authenticate === 'function' ) { await server . authenticate ( request , reply ) ; return }
179177 if ( typeof ( app as any ) . authenticate === 'function' ) { await ( app as any ) . authenticate ( request , reply ) ; return }
180- try { await request . jwtVerify ( ) } catch ( e ) { reply . status ( 401 ) . send ( { error : 'Unauthorized' } ) }
178+ try { await request . jwtVerify ( ) } catch { reply . status ( 401 ) . send ( { error : 'Unauthorized' } ) }
181179 } ] ,
182180 } , async ( request : FastifyRequest < { Params : { platform : string } } > , reply : FastifyReply ) => {
183181 const userId = ( request . user as any ) . id ;
@@ -198,7 +196,7 @@ export async function connectRoutes(app: FastifyInstance) {
198196 } ,
199197 } ) ;
200198 return { success : true } ;
201- } catch ( error ) {
199+ } catch {
202200 return reply . status ( 404 ) . send ( { error : 'Connection not found' } ) ;
203201 }
204202 } ) ;
0 commit comments