Added loading indicator
This commit is contained in:
@@ -30,7 +30,7 @@ export class GoogleAuthManager {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
checkConnection(): void {
|
||||
async checkConnection(): Promise<void> {
|
||||
this.state.checking = true;
|
||||
this.state.error = null;
|
||||
|
||||
@@ -38,12 +38,39 @@ export class GoogleAuthManager {
|
||||
const token = localStorage.getItem('google_refresh_token');
|
||||
const email = localStorage.getItem('google_user_email');
|
||||
|
||||
this.state.isConnected = !!token;
|
||||
this.state.token = token;
|
||||
this.state.userEmail = email;
|
||||
if (!token) {
|
||||
this.state.isConnected = false;
|
||||
this.state.token = null;
|
||||
this.state.userEmail = null;
|
||||
return;
|
||||
}
|
||||
|
||||
// Verify the token by calling our backend endpoint
|
||||
const response = await fetch('/private/api/google/auth/check', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ refreshToken: token })
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
this.state.isConnected = true;
|
||||
this.state.token = token;
|
||||
this.state.userEmail = email;
|
||||
} else {
|
||||
// Token is invalid or expired
|
||||
await this.disconnectGoogle();
|
||||
if (response.status === 401) {
|
||||
this.state.error = 'Google session expired. Please reconnect.';
|
||||
} else {
|
||||
this.state.error = 'Failed to verify connection.';
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error checking connection:', error);
|
||||
this.state.error = 'Failed to check connection status';
|
||||
this.state.error = 'Failed to verify connection status';
|
||||
this.state.isConnected = false;
|
||||
} finally {
|
||||
this.state.checking = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user