fraud-detection-url / static /js /firebase-config.js
kh03's picture
Upload 7 files
0a08a10 verified
// Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyD4iOeFtD-hETA5-8qWhWh9wRk-PNdhVKj-E",
authDomain: "fraudtest-23c54.firebaseapp.com",
projectId: "fraudtest-23c54",
storageBucket: "fraudtest-23c54.appspot.com",
messagingSenderId: "265409594914",
appId: "1:265409594914:web:e199246e50428971c32c7b"
};
// Initialize Firebase
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
// Firebase authentication service
const auth = firebase.auth();
// Firebase Auth library with utility functions
const firebaseAuth = {
// Check authentication state
checkAuthState: function(callback) {
auth.onAuthStateChanged(callback);
},
// Sign up with email and password
signUpWithEmail: function(email, password) {
return auth.createUserWithEmailAndPassword(email, password);
},
// Alias for signUpWithEmail to match template calls
signUp: function(email, password) {
return this.signUpWithEmail(email, password);
},
// Sign in with email and password
signInWithEmail: function(email, password) {
return auth.signInWithEmailAndPassword(email, password);
},
// Alias for signInWithEmail to match template calls
signIn: function(email, password) {
return this.signInWithEmail(email, password);
},
// Sign in with Google
signInWithGoogle: function() {
const provider = new firebase.auth.GoogleAuthProvider();
return auth.signInWithPopup(provider);
},
// Sign out
signOut: function() {
return auth.signOut();
},
// Reset password
resetPassword: function(email) {
return auth.sendPasswordResetEmail(email);
},
// Update user profile - Fixed to handle either string or object
updateProfile: function(displayNameOrProfileObj) {
const user = auth.currentUser;
if (user) {
// If it's just a string, it's the display name
if (typeof displayNameOrProfileObj === 'string') {
return user.updateProfile({
displayName: displayNameOrProfileObj
});
}
// Otherwise it's a profile object
return user.updateProfile(displayNameOrProfileObj);
}
return Promise.reject(new Error('No user is signed in'));
},
// Send email verification
sendEmailVerification: function() {
const user = auth.currentUser;
if (user) {
return user.sendEmailVerification();
}
return Promise.reject(new Error('No user is signed in'));
},
// Get current user
getCurrentUser: function() {
return auth.currentUser;
},
// Get user token
getUserToken: async function() {
const user = auth.currentUser;
if (user) {
return await user.getIdToken();
}
return null;
}
};
// Add global object for backend authentication
window.firebaseAuth = firebaseAuth;