Skip to content

Commit f5378b3

Browse files
authored
refactor(web): protect add duplicate script (#113)
* refactor(web): protect add duplicate script * refactor: add ssr support
1 parent 7187b5a commit f5378b3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/web.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,20 @@ export class GoogleAuthWeb extends WebPlugin implements GoogleAuthPlugin {
2222
}
2323

2424
loadScript() {
25-
var head = document.getElementsByTagName('head')[0];
26-
var script = document.createElement('script');
25+
const scriptId = 'gapi'
26+
const scriptEl = document?.getElementById(scriptId)
27+
28+
if (scriptEl) {
29+
return
30+
}
31+
32+
var head = document.getElementsByTagName('head')[0]
33+
var script = document.createElement('script')
34+
2735
script.type = 'text/javascript';
2836
script.defer = true;
2937
script.async = true;
38+
script.id = scriptId
3039
script.onload = this.platformJsLoaded;
3140
script.src = 'https://apis.google.com/js/platform.js';
3241
head.appendChild(script);

0 commit comments

Comments
 (0)