-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.js
43 lines (34 loc) · 1.42 KB
/
auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
if (location.protocol !== 'https:')console.error(`Replit authentication doesn't work with http:// normally. Please consider changing.`)
const repl_auth = function(settings) {
settings = {
id: settings.id,
onAuth: settings.onAuth || function(){window.location.reload()},
onStartAuth: settings.onStartAuth || function(){},
width: settings.width || 350,
height: settings.height || 500,
host: settings.host || location.host
}
if(settings.id && document.getElementById(settings.id)){
let btn = document.getElementById(settings.id);
btn.addEventListener('click',()=>{repl_auth_click(settings)})
}else{
console.error('Provide a valid button ID')
}
}
const repl_auth_complete = function(r,on,window) {
if (r.data !== 'auth_complete') {
return;
}
window.close();
on();
}
const repl_auth_click = function(settings) {
settings.onStartAuth();
window.addEventListener('message', (m)=>{repl_auth_complete(m,settings.onAuth,repl_auth_window)});
var left = (screen.width / 2) - ( settings.width / 2);
var top = (screen.height / 2) - (settings.height / 2);
var repl_auth_window = window.open(
location.protocol+'//repl.it/auth_with_repl_site?domain='+settings.host,
'_blank',
'modal =yes, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+settings.width+', height='+settings.height+', top='+top+', left='+left)
}