Skip to content

Commit

Permalink
Programmatically route based on auth state.
Browse files Browse the repository at this point in the history
  • Loading branch information
arvind committed Oct 5, 2023
1 parent 8500c9d commit 2d7c44f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/About.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<template>
<Header>
<template v-slot:subtitle>About Cartoons</template>
<template v-if="$route.params.persona" v-slot:subtitle>About Cartoons</template>
</Header>

<p v-if="$route.params.persona === 'pirate'">
Expand Down
4 changes: 4 additions & 0 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const router = createRouter({
routes: [
{
path: '/',
component: AboutVue
},
{
path: '/home',
component: Home
},
{
Expand Down
5 changes: 5 additions & 0 deletions src/stores/auth.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import {ref, computed} from 'vue';
import { defineStore } from 'pinia';
import { useRouter } from 'vue-router';

export const useAuthStore = defineStore('auth', () => {
const email = ref('');

const authenticated = ref(false);

const router = useRouter();

function toggleAuth() {
authenticated.value = email.value !== '' && !authenticated.value;
if (authenticated.value) router.push('/home')
else router.push('/');
}

return {email, authenticated, toggleAuth}
Expand Down

0 comments on commit 2d7c44f

Please sign in to comment.