automatically show firebase auth providers
This commit is contained in:
parent
decdacc812
commit
f12567ce55
1 changed files with 22 additions and 3 deletions
|
|
@ -183,7 +183,7 @@
|
|||
|
||||
<div id="error" class="error-msg"></div>
|
||||
|
||||
<button id="google-btn" class="btn" onclick="googleSignIn()">
|
||||
<button id="google-btn" class="btn" onclick="googleSignIn()" style="display:none">
|
||||
<svg class="google-icon" viewBox="0 0 24 24">
|
||||
<path
|
||||
fill="#4285F4"
|
||||
|
|
@ -205,9 +205,9 @@
|
|||
Sign in with Google
|
||||
</button>
|
||||
|
||||
<div class="divider">or</div>
|
||||
<div class="divider" style="display:none">or</div>
|
||||
|
||||
<form id="email-form" onsubmit="emailAuth(event)">
|
||||
<form id="email-form" onsubmit="emailAuth(event)" style="display:none">
|
||||
<div class="form-group">
|
||||
<input type="email" id="email" placeholder="Email" required autocomplete="email" />
|
||||
</div>
|
||||
|
|
@ -277,6 +277,25 @@
|
|||
const auth = getAuth(fbApp);
|
||||
const provider = new GoogleAuthProvider();
|
||||
|
||||
// Reveal auth providers based on Firebase project config (non-blocking)
|
||||
fetch(`https://www.googleapis.com/identitytoolkit/v3/relyingparty/getProjectConfig?key=${firebaseConfig.apiKey}`)
|
||||
.then(res => res.ok ? res.json() : null)
|
||||
.then(data => {
|
||||
if (!data) return;
|
||||
const providers = (data.idpConfig || []).filter(p => p.enabled).map(p => p.provider);
|
||||
const hasGoogle = providers.includes('google.com');
|
||||
const hasPassword = (data.signIn || {}).allowPasswordSignup !== false;
|
||||
if (hasGoogle) document.getElementById('google-btn').style.display = '';
|
||||
if (hasPassword) document.getElementById('email-form').style.display = '';
|
||||
if (hasGoogle && hasPassword) document.querySelector('.divider').style.display = '';
|
||||
})
|
||||
.catch(() => {
|
||||
// Fallback: show everything if the check fails
|
||||
document.getElementById('google-btn').style.display = '';
|
||||
document.getElementById('email-form').style.display = '';
|
||||
document.querySelector('.divider').style.display = '';
|
||||
});
|
||||
|
||||
function showError(msg) {
|
||||
const el = document.getElementById('error');
|
||||
el.textContent = msg;
|
||||
|
|
|
|||
Loading…
Reference in a new issue