Skip to content

Instantly share code, notes, and snippets.

@matthewmaribojoc

matthewmaribojoc/Feed.vue

Last active Jun 8, 2021
Embed
What would you like to do?
<template>
<h1> Feed </h1>
<h3> This page is for users only </h3>
</template>
<script setup>
import firebase from 'firebase'
import { useRouter } from 'vue-router'
import { onBeforeUnmount } from 'vue'
const router = useRouter()
const authListener = firebase.auth().onAuthStateChanged(function(user) {
if (!user) { // not logged in
alert('you must be logged in to view this. redirecting to the home page')
router.push('/')
}
})
onBeforeUnmount(() => {
// clear up listener
authListener()
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment