Implement user auth with Firebase

This commit is contained in:
Conor McNamara
2023-03-06 20:23:54 +00:00
parent 2d41b93932
commit ef9b4847af
24 changed files with 1402 additions and 1258 deletions

View File

@ -1,9 +1,29 @@
import {getAuth, onAuthStateChanged} from "firebase/auth"
import app from '../api/firebase';
function isAuth(to, from, next) {
console.log("Checking auth")
const auth = getAuth(app)
onAuthStateChanged(auth, (user) => {
// user is logged in, continue to page
if (user) {
return next()
}
// user is logged out, send back to home page
else {
return next({path: "/"})
}
})
}
function loadPage(component) {
return () => import(`@/pages/${component}.vue`)
}
export default [
{path: "/", component:loadPage("MapPage")},
{path: "/insights", component:loadPage("InsightsPage")},
{path: "/signup", component:loadPage("signup")},
{path: "/login", component:loadPage("loginpage")}
{path: "/secure", component:loadPage('SecurePage'), beforeEnter: isAuth},
{path: "/signup", component:loadPage('SignUpPage')},
{path: "/login", component:loadPage('LoginPage')},
]