11const express = require ( 'express' ) ;
22const router = express . Router ( )
3- const axios = require ( 'axios' )
3+ const { get , post } = require ( 'axios' )
44var session = require ( 'express-session' )
55const { github} = require ( './../../config/config' )
66var clientId = github . clientId
77var clientSecret = github . clientSecret
88
99router . get ( '/getUserProfile' , ( req , res ) => {
1010 username = req . query . username
11- axios
12- . get ( `https://api.github.com/users/${ username } ` )
11+ get ( `https://api.github.com/users/${ username } ` )
1312 . then ( resp => {
1413 res . send ( resp . data )
1514 } )
@@ -24,8 +23,7 @@ router.get('/getUserProfile',(req,res)=>{
2423 console . log ( "username" , req . query . username )
2524 if ( githubLogin == "false" ) {
2625 console . log ( "! githubLogin is " , githubLogin )
27- axios
28- . get ( `https://api.github.com/users/${ username } /orgs` )
26+ get ( `https://api.github.com/users/${ username } /orgs` )
2927 . then ( resp => {
3028 res . send ( resp . data )
3129 } )
@@ -39,8 +37,7 @@ router.get('/getUserProfile',(req,res)=>{
3937 }
4038 }
4139 console . log ( config )
42- axios
43- . get ( `https://api.github.com/user/orgs` , config = config )
40+ get ( `https://api.github.com/user/orgs` , config = config )
4441 . then ( resp => {
4542 console . log ( resp . data . length )
4643 return resp . data
@@ -52,8 +49,7 @@ router.get('/getUserProfile',(req,res)=>{
5249 "Authorization" :`token ${ oauth_token } `
5350 }
5451 }
55- axios
56- . get ( `https://api.github.com/users/${ username } /orgs` , config = config )
52+ get ( `https://api.github.com/users/${ username } /orgs` , config = config )
5753 . then ( resp1 => {
5854 console . log ( resp1 . data . length )
5955 var flag , elem ;
@@ -86,16 +82,14 @@ router.get('/getUserProfile',(req,res)=>{
8682 console . log ( config )
8783 username = req . query . username
8884 if ( username !== undefined ) {
89- axios
90- . get ( `https://api.github.com/users/${ username } /repos` , config = config )
85+ get ( `https://api.github.com/users/${ username } /repos` , config = config )
9186 . then ( resp => {
9287 res . send ( resp . data )
9388 } )
9489 . catch ( err => res . json ( { "error" :err } ) )
9590 }
9691 else {
97- axios
98- . get ( `https://api.github.com/user/repos` , config = config )
92+ get ( `https://api.github.com/user/repos` , config = config )
9993 . then ( resp => {
10094 res . send ( resp . data )
10195 } )
@@ -114,8 +108,7 @@ router.get('/getUserProfile',(req,res)=>{
114108 "Authorization" :`token ${ oauth_token } `
115109 }
116110 }
117- axios
118- . get ( `https://api.github.com/user` , config = config )
111+ get ( `https://api.github.com/user` , config = config )
119112 . then ( resp => {
120113 res . cookie ( 'username' , resp . data [ "login" ] , { expires : new Date ( Date . now ( ) + + 315360000000 ) } ) //saves username for upcoming queries of logedin user
121114 res . json ( resp . data )
@@ -124,8 +117,7 @@ router.get('/getUserProfile',(req,res)=>{
124117 }
125118 else {
126119 console . log ( "not github login" )
127- axios
128- . get ( `https://api.github.com/users/${ username } ` )
120+ get ( `https://api.github.com/users/${ username } ` )
129121 . then ( resp => {
130122 res . cookie ( 'username' , resp . data [ "login" ] , { expires : new Date ( Date . now ( ) + + 315360000000 ) } ) //saves username for upcoming queries of logedin user
131123 res . json ( resp . data )
@@ -143,7 +135,7 @@ router.get('/auth',(req,res)=>{
143135 } ;
144136
145137 const opts = { headers : { accept : 'application/json' } } ;
146- axios . post ( `https://github.com/login/oauth/access_token` , body , opts ) .
138+ post ( `https://github.com/login/oauth/access_token` , body , opts ) .
147139 then ( res => {
148140 return { token :res . data [ 'access_token' ] , refresh :res . data [ 'refresh_token' ] }
149141 } )
@@ -173,8 +165,7 @@ router.get('/auth',(req,res)=>{
173165 }
174166 }
175167
176- axios
177- . get ( `https://api.github.com/user` , config = config )
168+ get ( `https://api.github.com/user` , config = config )
178169 . then ( resp => {
179170 res . cookie ( 'username' , resp . data [ "login" ] , { expires : new Date ( Date . now ( ) + + 315360000000 ) } ) //saves username for upcoming queries of logedin user
180171 if ( resp . data . type == "User" ) {
0 commit comments