-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
124 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<script setup lang="ts"> | ||
import { storeToRefs } from 'pinia'; | ||
import { onBeforeMount, ref } from 'vue'; | ||
import { useRouter } from 'vue-router'; | ||
import { useAuthStore } from '@/store'; | ||
import { RouteNames } from '@/utils/constants'; | ||
import type { Ref } from 'vue'; | ||
// Store | ||
const { getIsAuthenticated } = storeToRefs(useAuthStore()); | ||
// State | ||
const ready: Ref<boolean> = ref(false); | ||
// Actions | ||
onBeforeMount( async () => { | ||
const router = useRouter(); | ||
if( !getIsAuthenticated.value ) { | ||
router.replace({ name: RouteNames.LOGIN }); | ||
} | ||
else { | ||
ready.value = true; | ||
} | ||
}); | ||
</script> | ||
|
||
<template> | ||
<slot v-if="ready" /> | ||
</template> | ||
|
||
<style lang="scss" scoped> | ||
h3 { | ||
font-weight: bold; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<script setup lang="ts"> | ||
import { storeToRefs } from 'pinia'; | ||
import { onBeforeMount, ref } from 'vue'; | ||
import { useRouter } from 'vue-router'; | ||
import { useAuthStore, useObjectStore } from '@/store'; | ||
import { RouteNames } from '@/utils/constants'; | ||
import type { Ref } from 'vue'; | ||
// Props | ||
type Props = { | ||
objectId: string | ||
}; | ||
const props = withDefaults(defineProps<Props>(), {}); | ||
// Store | ||
const objectStore = useObjectStore(); | ||
const { getIsAuthenticated } = storeToRefs(useAuthStore()); | ||
// State | ||
const ready: Ref<boolean> = ref(false); | ||
// Actions | ||
const router = useRouter(); | ||
onBeforeMount( async () => { | ||
let isPublic = false; | ||
if( props.objectId ) { | ||
const head = await objectStore.headObject(props.objectId); | ||
isPublic = head?.status === 204; | ||
} | ||
if( !isPublic && !getIsAuthenticated.value ) { | ||
router.replace({ name: RouteNames.LOGIN }); | ||
} | ||
else { | ||
ready.value = true; | ||
} | ||
}); | ||
</script> | ||
|
||
<template> | ||
<slot v-if="ready" /> | ||
</template> | ||
|
||
<style lang="scss" scoped> | ||
h3 { | ||
font-weight: bold; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as RequireAuth } from './RequireAuth.vue'; | ||
export { default as RequirePublicOrAuth } from './RequirePublicOrAuth.vue'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters