Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Google Login button disappearing issue #3197

Merged
merged 22 commits into from
Jan 19, 2025
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 39 additions & 16 deletions core/gui/src/app/common/service/user/google-auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,45 @@ export class GoogleAuthService {
private _googleCredentialResponse = new Subject<CredentialResponse>();
constructor(private http: HttpClient) {}
public googleAuthInit(parent: HTMLElement | null) {
this.http.get(`${AppSettings.getApiEndpoint()}/auth/google/clientid`, { responseType: "text" }).subscribe({
next: response => {
window.onGoogleLibraryLoad = () => {
window.google.accounts.id.initialize({
client_id: response,
callback: (auth: CredentialResponse) => {
this._googleCredentialResponse.next(auth);
},
});
window.google.accounts.id.renderButton(parent, { width: 200 });
window.google.accounts.id.prompt();
};
},
error: (err: unknown) => {
console.error(err);
},
this.waitForGoogleScript(2000)
.then(() => {
this.http.get(`${AppSettings.getApiEndpoint()}/auth/google/clientid`, { responseType: "text" }).subscribe({
next: response => {
window.google.accounts.id.initialize({
client_id: response,
callback: (auth: CredentialResponse) => {
this._googleCredentialResponse.next(auth);
},
});
window.google.accounts.id.renderButton(parent, { width: 200 });
window.google.accounts.id.prompt();
},
error: (err: unknown) => {
console.error(err);
},
});
})
.catch(err => {
console.error(err.message);
});
}

private waitForGoogleScript(timeout: number): Promise<void> {
return new Promise((resolve, reject) => {
const interval = 100;
let elapsedTime = 0;

const checkGoogleScript = setInterval(() => {
elapsedTime += interval;

if (typeof window.google !== "undefined") {
clearInterval(checkGoogleScript);
resolve();
} else if (elapsedTime >= timeout) {
clearInterval(checkGoogleScript);
reject(new Error("Google script is not loaded or not available within the timeout period."));
}
}, interval);
});
}

Expand Down
Loading