Skip to content

Commit e4fc666

Browse files
committed
Google login robustness
There were 2 problems with google login. 1 - The very first time you log in on an account, if you don't check the box in the Google popup, then login fails. Now asks you to login again. 2 - There was a timing issue and sometimes the user profile pic did not show up.
1 parent bd4e533 commit e4fc666

4 files changed

Lines changed: 244 additions & 108 deletions

File tree

src/services/google-auth.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,25 @@ class GoogleAuthService {
126126
}
127127
}
128128

129+
/**
130+
* Wait until the backend handshake token is available before exchanging OAuth codes.
131+
*/
132+
async ensureHandshakeReady(): Promise<void> {
133+
if (this._handshakeToken) {
134+
return;
135+
}
136+
const maxAttempts = 15;
137+
const delayMs = 200;
138+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
139+
await this.initHandshake();
140+
if (this._handshakeToken) {
141+
return;
142+
}
143+
await new Promise((resolve) => setTimeout(resolve, delayMs));
144+
}
145+
throw new Error('Google Auth handshake not ready');
146+
}
147+
129148
/**
130149
* Refreshes the access token using the stored refresh token.
131150
* @returns A Promise that resolves to the new access token.
@@ -226,8 +245,12 @@ class GoogleAuthService {
226245
* @returns A Promise that resolves to an object containing access_token, refresh_token, and expires_in.
227246
*/
228247
async getRefreshToken() {
229-
if (!this._handshakeToken || !this._code) {
230-
throw new Error('Handshake token or authorization code not available.');
248+
if (!this._code) {
249+
throw new Error('Authorization code not available.');
250+
}
251+
await this.ensureHandshakeReady();
252+
if (!this._handshakeToken) {
253+
throw new Error('Handshake token not available.');
231254
}
232255

233256
try {

src/utils/i18n/locales/en/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
"user-folder": "User Folder Name",
106106
"google-drive-folder": "Google Drive Folder Name",
107107
"googleLoginTooltip": "Sign in with your Google account to access files stored in Google Drive.",
108+
"googleSigningIn": "Signing in...",
108109
"googlogoutTooltip": "Sign out of your Google account.",
109110
"not-google-drive-file": "This file can not be saved to Google Drive because it was not associated with Google Drive! Please try saving it to XRP!",
110111
"editGoogleLoginRequired": "This file is stored in Google Drive. Please sign back in to Google Drive to edit and save it.",

src/utils/i18n/locales/es/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
"username": "Nombre de Usuario",
190190
"googlesignin": "Iniciar sesión con Google",
191191
"googleLoginTooltip": "Inicie sesión con su cuenta de Google para acceder a los archivos almacenados en Google Drive.",
192+
"googleSigningIn": "Iniciando sesión...",
192193
"googlogoutTooltip": "Cerrar sesión de su cuenta de Google.",
193194
"login": "Inicio de Sesión de Google",
194195
"login-desc": "El modo de usuario está configurado actualmente en Usuario de Google. Por favor inicie sesión en su cuenta de Google para editar sus archivos. Haga clic en el botón Iniciar Sesión en Google a continuación.",

0 commit comments

Comments
 (0)