feat(accounts): ability to reset passwords
This commit is contained in:
parent
9fd1256da3
commit
148506f68c
5 changed files with 40 additions and 1 deletions
|
|
@ -2433,6 +2433,13 @@
|
|||
<button id="email-signin-btn" class="btn-primary" style="flex: 1">Sign In</button>
|
||||
<button id="email-signup-btn" class="btn-secondary" style="flex: 1">Sign Up</button>
|
||||
</div>
|
||||
<button
|
||||
id="reset-password-btn"
|
||||
class="btn-secondary"
|
||||
style="width: 100%; margin-top: 10px; font-size: 0.9rem"
|
||||
>
|
||||
Forgot Password?
|
||||
</button>
|
||||
<button
|
||||
id="cancel-email-auth-btn"
|
||||
class="btn-secondary"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {
|
|||
onAuthStateChanged,
|
||||
signInWithEmailAndPassword,
|
||||
createUserWithEmailAndPassword,
|
||||
sendPasswordResetEmail,
|
||||
} from 'https://www.gstatic.com/firebasejs/10.7.1/firebase-auth.js';
|
||||
|
||||
export class AuthManager {
|
||||
|
|
@ -82,6 +83,21 @@ export class AuthManager {
|
|||
}
|
||||
}
|
||||
|
||||
async sendPasswordReset(email) {
|
||||
if (!auth) {
|
||||
alert('Firebase is not configured.');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await sendPasswordResetEmail(auth, email);
|
||||
alert(`Password reset email sent to ${email}`);
|
||||
} catch (error) {
|
||||
console.error('Password reset failed:', error);
|
||||
alert(`Failed to send reset email: ${error.message}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async signOut() {
|
||||
if (!auth) return;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// js/firebase/config.js
|
||||
//js/accounts/config.js
|
||||
import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js';
|
||||
import { getAuth, GoogleAuthProvider } from 'https://www.gstatic.com/firebasejs/10.7.1/firebase-auth.js';
|
||||
import { getDatabase } from 'https://www.gstatic.com/firebasejs/10.7.1/firebase-database.js';
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
//js/accounts/pocketbase.js
|
||||
import PocketBase from 'pocketbase';
|
||||
import { db } from '../db.js';
|
||||
import { authManager } from './auth.js';
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ export function initializeSettings(scrobbler, player, api, ui) {
|
|||
const passwordInput = document.getElementById('auth-password');
|
||||
const signInBtn = document.getElementById('email-signin-btn');
|
||||
const signUpBtn = document.getElementById('email-signup-btn');
|
||||
const resetPasswordBtn = document.getElementById('reset-password-btn');
|
||||
|
||||
if (toggleEmailBtn && authContainer && authButtonsContainer) {
|
||||
toggleEmailBtn.addEventListener('click', () => {
|
||||
|
|
@ -88,6 +89,20 @@ export function initializeSettings(scrobbler, player, api, ui) {
|
|||
});
|
||||
}
|
||||
|
||||
if (resetPasswordBtn) {
|
||||
resetPasswordBtn.addEventListener('click', async () => {
|
||||
const email = emailInput.value;
|
||||
if (!email) {
|
||||
alert('Please enter your email address to reset your password.');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await authManager.sendPasswordReset(email);
|
||||
} catch {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const lastfmConnectBtn = document.getElementById('lastfm-connect-btn');
|
||||
const lastfmStatus = document.getElementById('lastfm-status');
|
||||
const lastfmToggle = document.getElementById('lastfm-toggle');
|
||||
|
|
|
|||
Loading…
Reference in a new issue