From 9df2e41a7e47079ce7228cb2f25baed86e9c279d Mon Sep 17 00:00:00 2001 From: Alberto Cabrera Date: Sun, 14 Jan 2024 00:56:35 +0800 Subject: [PATCH 1/4] Added refresh tokens --- src/auth/providers/queries.ts | 3 +++ src/auth/providers/useSignInWithFacebook.ts | 4 ++++ src/auth/providers/useSignInWithGoogle.ts | 4 ++++ src/auth/providers/useSignInWithTheKey.ts | 11 +++++++++++ 4 files changed, 22 insertions(+) diff --git a/src/auth/providers/queries.ts b/src/auth/providers/queries.ts index b23dc06ef7..74f1f91494 100644 --- a/src/auth/providers/queries.ts +++ b/src/auth/providers/queries.ts @@ -6,6 +6,7 @@ export const SIGN_IN_WITH_THE_KEY_MUTATION = gql` input: { keyAccessToken: $accessToken, anonymousUid: $anonymousUid } ) { token + refreshToken } } `; @@ -16,6 +17,7 @@ export const SIGN_IN_WITH_FACEBOOK_MUTATION = gql` input: { fbAccessToken: $accessToken, anonymousUid: $anonymousUid } ) { token + refreshToken } } `; @@ -24,6 +26,7 @@ export const SIGN_IN_WITH_GOOGLE_MUTATION = gql` mutation SignInWithGoogle($idToken: String!, $anonymousUid: String) { loginWithGoogle(input: { idToken: $idToken, anonymousUid: $anonymousUid }) { token + refreshToken } } `; diff --git a/src/auth/providers/useSignInWithFacebook.ts b/src/auth/providers/useSignInWithFacebook.ts index 4f0a12d22a..0c47b95119 100644 --- a/src/auth/providers/useSignInWithFacebook.ts +++ b/src/auth/providers/useSignInWithFacebook.ts @@ -6,6 +6,7 @@ import { setAuthToken, getAnonymousUid, deleteAnonymousUid, + setMissionHubRefreshToken, } from '../authStore'; import { AuthError } from '../constants'; import { rollbar } from '../../utils/rollbar.config'; @@ -69,6 +70,9 @@ export const useSignInWithFacebook = () => { if (data?.loginWithFacebook?.token) { await setAuthToken(data.loginWithFacebook.token); + await setMissionHubRefreshToken( + data.loginWithFacebook?.refreshToken || '', + ); await deleteAnonymousUid(); } else { throw new Error('apiSignInWithFacebook did not return an access token'); diff --git a/src/auth/providers/useSignInWithGoogle.ts b/src/auth/providers/useSignInWithGoogle.ts index 6f4226c871..6692435d22 100644 --- a/src/auth/providers/useSignInWithGoogle.ts +++ b/src/auth/providers/useSignInWithGoogle.ts @@ -9,6 +9,7 @@ import { setAuthToken, getAnonymousUid, deleteAnonymousUid, + setMissionHubRefreshToken, } from '../authStore'; import { AuthError } from '../constants'; import { rollbar } from '../../utils/rollbar.config'; @@ -90,6 +91,9 @@ export const useSignInWithGoogle = () => { if (data?.loginWithGoogle?.token) { await setAuthToken(data.loginWithGoogle.token); + await setMissionHubRefreshToken( + data.loginWithGoogle?.refreshToken || '', + ); await deleteAnonymousUid(); } else { throw new Error('apiSignInWithGoogle did not return an access token'); diff --git a/src/auth/providers/useSignInWithTheKey.ts b/src/auth/providers/useSignInWithTheKey.ts index a25b3effa0..c525a24b79 100644 --- a/src/auth/providers/useSignInWithTheKey.ts +++ b/src/auth/providers/useSignInWithTheKey.ts @@ -19,6 +19,7 @@ import { getTheKeyRefreshToken, setTheKeyRefreshToken, deleteAnonymousUid, + setMissionHubRefreshToken, } from '../authStore'; import { AuthError } from '../constants'; import { rollbar } from '../../utils/rollbar.config'; @@ -105,9 +106,11 @@ export const useSignInWithTheKey = () => { const makeAccessTokenRequest = useCallback( async (request: ApiRouteConfigEntry, params: string) => { + console.log('request', request); const { access_token, refresh_token } = ((await dispatch( callApi(request, {}, params), )) as unknown) as { access_token: string; refresh_token?: string }; + console.log(`refresh_token from the key`, refresh_token); refresh_token && setTheKeyRefreshToken(refresh_token); return access_token; }, @@ -181,18 +184,26 @@ export const useSignInWithTheKey = () => { try { const accessToken = await getAccessToken(options); + console.log('accessToken', accessToken); const ticket = await getTicket(accessToken); + console.log('ticket', ticket); const anonymousUid = await getAnonymousUid(); + console.log('anonymousUid', anonymousUid); const { data } = await apiSignInWithTheKey({ variables: { accessToken: ticket, anonymousUid, }, }); + // @ts-ignore + console.log(`refresh_token from graphql`, data); if (data?.loginWithTheKey?.token) { await setAuthToken(data.loginWithTheKey.token); + await setMissionHubRefreshToken( + data.loginWithTheKey?.refreshToken || '', + ); await deleteAnonymousUid(); } else { throw new Error('apiSignInWithTheKey did not return an access token'); From ed96fb5c20721c5d34b383379b1b6d904851b8a0 Mon Sep 17 00:00:00 2001 From: uriel54321 <83802273+uriel54321@users.noreply.github.com> Date: Sun, 14 Jan 2024 13:28:05 +0800 Subject: [PATCH 2/4] Update useSignInWithTheKey.ts Removed the loggers --- src/auth/providers/useSignInWithTheKey.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/auth/providers/useSignInWithTheKey.ts b/src/auth/providers/useSignInWithTheKey.ts index c525a24b79..156b7cc318 100644 --- a/src/auth/providers/useSignInWithTheKey.ts +++ b/src/auth/providers/useSignInWithTheKey.ts @@ -106,11 +106,9 @@ export const useSignInWithTheKey = () => { const makeAccessTokenRequest = useCallback( async (request: ApiRouteConfigEntry, params: string) => { - console.log('request', request); const { access_token, refresh_token } = ((await dispatch( callApi(request, {}, params), )) as unknown) as { access_token: string; refresh_token?: string }; - console.log(`refresh_token from the key`, refresh_token); refresh_token && setTheKeyRefreshToken(refresh_token); return access_token; }, @@ -184,12 +182,9 @@ export const useSignInWithTheKey = () => { try { const accessToken = await getAccessToken(options); - console.log('accessToken', accessToken); const ticket = await getTicket(accessToken); - console.log('ticket', ticket); const anonymousUid = await getAnonymousUid(); - console.log('anonymousUid', anonymousUid); const { data } = await apiSignInWithTheKey({ variables: { accessToken: ticket, @@ -197,7 +192,6 @@ export const useSignInWithTheKey = () => { }, }); // @ts-ignore - console.log(`refresh_token from graphql`, data); if (data?.loginWithTheKey?.token) { await setAuthToken(data.loginWithTheKey.token); From 82da66cb7a6392f5dc121a65c471f8ff89c8f25b Mon Sep 17 00:00:00 2001 From: uriel54321 <83802273+uriel54321@users.noreply.github.com> Date: Sun, 14 Jan 2024 19:02:01 +0800 Subject: [PATCH 3/4] Update useSignInWithTheKey.ts removed "// @ts-ignore" --- src/auth/providers/useSignInWithTheKey.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/auth/providers/useSignInWithTheKey.ts b/src/auth/providers/useSignInWithTheKey.ts index 156b7cc318..33817c6c27 100644 --- a/src/auth/providers/useSignInWithTheKey.ts +++ b/src/auth/providers/useSignInWithTheKey.ts @@ -191,8 +191,7 @@ export const useSignInWithTheKey = () => { anonymousUid, }, }); - // @ts-ignore - + if (data?.loginWithTheKey?.token) { await setAuthToken(data.loginWithTheKey.token); await setMissionHubRefreshToken( From d27d2e0c6d13cd721fa6911544afb02eadb75dfe Mon Sep 17 00:00:00 2001 From: Jescart Baculi <98641036+jbacs@users.noreply.github.com> Date: Mon, 15 Jan 2024 11:10:45 +0800 Subject: [PATCH 4/4] removed whitespace --- src/auth/providers/useSignInWithTheKey.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/auth/providers/useSignInWithTheKey.ts b/src/auth/providers/useSignInWithTheKey.ts index 33817c6c27..3f31272828 100644 --- a/src/auth/providers/useSignInWithTheKey.ts +++ b/src/auth/providers/useSignInWithTheKey.ts @@ -191,7 +191,7 @@ export const useSignInWithTheKey = () => { anonymousUid, }, }); - + if (data?.loginWithTheKey?.token) { await setAuthToken(data.loginWithTheKey.token); await setMissionHubRefreshToken(