@@ -37,10 +37,10 @@ import type {
3737} from '../utils/auth/types' ;
3838import {
3939 addAccount ,
40- authGitHub ,
40+ exchangeAuthCodeForAccessToken ,
4141 getAccountUUID ,
42- getToken ,
4342 hasAccounts ,
43+ performGitHubOAuth ,
4444 refreshAccount ,
4545 removeAccount ,
4646} from '../utils/auth/utils' ;
@@ -405,22 +405,36 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
405405 return hasAccounts ( auth ) ;
406406 } , [ auth ] ) ;
407407
408+ /**
409+ * Note: although we call this "Login with GitHub App", this function actually
410+ * authenticates via a predefined "Gitify" GitHub OAuth App.
411+ */
408412 const loginWithGitHubApp = useCallback ( async ( ) => {
409- const { authCode } = await authGitHub ( ) ;
410- const { token } = await getToken ( authCode ) ;
413+ const { authCode } = await performGitHubOAuth (
414+ Constants . DEFAULT_AUTH_OPTIONS ,
415+ ) ;
416+ const token = await exchangeAuthCodeForAccessToken ( authCode ) ;
411417 const hostname = Constants . DEFAULT_AUTH_OPTIONS . hostname ;
412418
413419 const updatedAuth = await addAccount ( auth , 'GitHub App' , token , hostname ) ;
414420
415421 persistAuth ( updatedAuth ) ;
416422 } , [ auth , persistAuth ] ) ;
417423
424+ /**
425+ * Login with custom GitHub OAuth App
426+ */
418427 const loginWithOAuthApp = useCallback (
419428 async ( data : LoginOAuthAppOptions ) => {
420- const { authOptions, authCode } = await authGitHub ( data ) ;
421- const { token, hostname } = await getToken ( authCode , authOptions ) ;
429+ const { authOptions, authCode } = await performGitHubOAuth ( data ) ;
430+ const token = await exchangeAuthCodeForAccessToken ( authCode , authOptions ) ;
422431
423- const updatedAuth = await addAccount ( auth , 'OAuth App' , token , hostname ) ;
432+ const updatedAuth = await addAccount (
433+ auth ,
434+ 'OAuth App' ,
435+ token ,
436+ authOptions . hostname ,
437+ ) ;
424438
425439 persistAuth ( updatedAuth ) ;
426440 } ,
0 commit comments