Using firebase SDK in netlify functions

I have this userSignIn code that was working fine in my server side js:

const userSignIn = async(event) => {
    const signInEmail = LoginUserEmail.value;
    const signInPassword = LoginUserPassword.value;
    signInWithEmailAndPassword(auth, signInEmail, signInPassword)
    .then((userCredential) => {
        const user = userCredential.user;
    .catch((error) => {
        const errorCode = error.code;
        const errorMessage = error.message;
        console.log(errorCode + errorMessage)

I am trying to turn it into a netlify function so that my firebase keys aren’t exposed. So far this is what I have (and I’m not sure if I’m close to getting it correct or not)

var {initializeApp} = require('firebase/app')
var {getAuth,signInWithEmailAndPassword} = require('firebase/auth')

const firebaseApiKey = process.env.FIREBASE_API_KEY;
const firebaseAuthDomain = process.env.FIREBASE_AUTH_DOMAIN;    
const firebaseProjectID = process.env.FIREBASE_PROJECT_ID;
const firebaseStorageBucket = process.env.FIREBASE_STORAGE_BUCKET;
const firebaseMessagingSenderID = process.env.FIREBASE_MESSAGING_SENDER_ID;
const firebaseAppID = process.env.FIREBASE_APP_ID;

const firebaseConfig = {
    apiKey: firebaseApiKey,
    authDomain: firebaseAuthDomain,
    projectId: firebaseProjectID,
    storageBucket: firebaseStorageBucket,
    messagingSenderId: firebaseMessagingSenderID,
    appId: firebaseAppID 

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
exports.handler = async (event) => {
    try {
        const signInEmail =;
        const signInPassword = event.queryStringParameters.password;
    const  signinUser = await signInWithEmailAndPassword(auth, {signInEmail}, {signInPassword})
        .then((userCredential) => {
            const user = userCredential.user;
            return user;
return callback(null,{
    statusCode: 200,
    body: JSON.stringify({ received: true }),
    send: JSON.stringify({ 
} catch (err) {
    return {
      statusCode: 400,
      body: `Error: ${err.message}`,

How would I get this to work as a netlify function? Also what would the event listener look like on my client side js?

Or is there a better way to go about handling this?

Thanks in advance!

Looks like we have been talking here: Reddit - Dive into anything