{"size": 1284, "ext": "js", "max_stars_repo_path": "src/app/create_account/create_account.js", "max_stars_repo_name": "ijaspreetbhatti/Team-Magpie-Scave", "max_stars_repo_stars_event_min_datetime": "2021-10-13T00:43:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-16T21:14:33.000Z", "max_issues_repo_path": "src/app/create_account/create_account.js", "max_issues_repo_name": "ijaspreetbhatti/Team-Magpie-Scave", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/app/create_account/create_account.js", "max_forks_repo_name": "ijaspreetbhatti/Team-Magpie-Scave", "max_forks_repo_forks_event_min_datetime": "2021-10-13T00:49:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-13T00:49:02.000Z"}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 27.9130434783, "max_line_length": 74, "alphanum_fraction": 0.6191588785}
import "./create_account.scss";
import { app } from "../services/firebase-service";

import {
    getAuth,
    createUserWithEmailAndPassword,
    updateProfile,
} from "firebase/auth";

const auth = getAuth(app);

document.getElementById("signup-form").addEventListener("submit", (e) => {
    e.preventDefault();
    console.log("gomi", SU_pass.value.length);
    if (SU_pass.value.length > 8) {
        wrongPass.innerHTML = "";
        const email = SU_email.value;
        const password = SU_pass.value;
        createAccount(email, password);
    } else {
        wrongPass.innerHTML = "Password needs to be 8 characters or more";
    }
});

function createAccount(email, password) {
    createUserWithEmailAndPassword(auth, email, password).then(
        (userCredential) => {
            console.log(userCredential);
            const user = userCredential.user;
            updateAccount({
                displayName: firstName.value + " " + lastName.value,
            });
        }
    );
}

function updateAccount(user) {
    updateProfile(auth.currentUser, {
        displayName: user.displayName,
    }).then(() => {
        console.log("Profile updated!");
        localStorage.setItem("user", JSON.stringify(userCredential));
        location.replace("/");
    });
}
