-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(katzencore): Added Authentication to Module
- Loading branch information
Maximilian Schleining
committed
Jul 15, 2024
1 parent
110c5ab
commit 376a4f3
Showing
14 changed files
with
1,015 additions
and
65 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<script setup lang="ts"> | ||
import { computed, type PropType } from 'vue' | ||
import { defineNuxtLink } from '#app' | ||
const props = defineProps( | ||
{ | ||
link: String, | ||
katId: { | ||
type: String, | ||
default: 'not-set', | ||
}, | ||
icon: { | ||
type: String, | ||
default: 'ArrowRight', | ||
}, | ||
buttonType: { | ||
type: String as PropType<'link' | 'button'>, | ||
default: 'link', | ||
}, | ||
color: { | ||
type: String as PropType<'bg-ce-primary' | 'bg-ce-secondary'>, | ||
default: 'bg-ce-primary', | ||
}, | ||
}, | ||
) | ||
const component = computed(() => { | ||
if (props.buttonType === 'link') return defineNuxtLink({}) | ||
return 'button' | ||
}) | ||
</script> | ||
|
||
<template> | ||
<component | ||
:is="component" | ||
:kat-e="katId" | ||
kat-t="text" | ||
class="rounded-full bg-red-400 py-3 px-4 | ||
text-center font-medium mt-3 | ||
flex flex-row items-center justify-center cursor-pointer | ||
select-none transition-all hover:opacity-90 active:opacity-80" | ||
:class="color" | ||
:to="link" | ||
> | ||
<span> | ||
<slot /> | ||
</span> | ||
</component> | ||
</template> |
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,11 @@ | ||
<script setup lang="ts"> | ||
</script> | ||
|
||
<template> | ||
|
||
</template> | ||
|
||
<style scoped> | ||
</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,78 @@ | ||
<script setup lang="ts"> | ||
import type { PropType } from 'vue' | ||
defineProps( | ||
{ | ||
src: { | ||
type: String, | ||
required: true, | ||
}, | ||
alt: { | ||
type: String, | ||
default: '', | ||
}, | ||
async: { | ||
type: Boolean, | ||
default: true, | ||
}, | ||
loading: { | ||
type: String as PropType<'lazy' | 'eager'>, | ||
default: 'eager', | ||
}, | ||
objectFit: { | ||
type: String as PropType<'cover' | 'contain' | 'fill' | 'none' | 'scale-down'>, | ||
default: 'cover', | ||
}, | ||
showPlaceholder: { | ||
type: Boolean, | ||
default: true, | ||
}, | ||
hideLoading: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
sizes: { | ||
type: String, | ||
default: '300px md:600px lg:700px xl:800px', | ||
}, | ||
}, | ||
) | ||
const hideLoadingAnimation = ref(false) | ||
const hidePlaceholder = () => { | ||
setTimeout(() => { | ||
hideLoadingAnimation.value = true | ||
}, 50) | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="relative overflow-hidden select-none"> | ||
<div | ||
v-if="!hideLoading" | ||
class="absolute -z-10 top-0 left-0 | ||
bg-gray-100 rounded w-full h-full | ||
transition-all duration-300" | ||
:class="{ 'opacity-0': hideLoadingAnimation, 'animate-pulse': !hideLoadingAnimation }" | ||
/> | ||
<NuxtImg | ||
ref="image" | ||
:src="src" | ||
:alt="alt" | ||
:decoding="async ? 'async' : 'sync'" | ||
:loading="loading" | ||
:placeholder="showPlaceholder ? true:15" | ||
:sizes="sizes" | ||
densities="1x" | ||
:placeholder-class="showPlaceholder? '' : 'opacity-0'" | ||
class="w-full h-full z-10 max-h-full" | ||
:style="{ objectFit }" | ||
@load="hidePlaceholder" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
</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,11 @@ | ||
<script setup lang="ts"> | ||
</script> | ||
|
||
<template> | ||
|
||
</template> | ||
|
||
<style scoped> | ||
</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,24 @@ | ||
export default defineNuxtRouteMiddleware(to => { | ||
|
||
const checkAuth = () => { | ||
const token = useCookie('token') | ||
if(!token.value) return false | ||
const jwt = require('jsonwebtoken'); | ||
return jwt.verify(token.value, useRuntimeConfig().secret) | ||
} | ||
|
||
console.log('Hello from the middleware!') | ||
// skip middleware on client | ||
if (import.meta.client) return | ||
//if route is /preview-login and user is already logged in, redirect to /preview | ||
if(to.path === '/preview-login') { | ||
if(checkAuth()) { | ||
return '/preview' | ||
} | ||
} | ||
//route to is /preview | ||
if(to.path !== '/preview') return; | ||
if (!checkAuth()) { | ||
return '/preview-login' | ||
} | ||
}) |
Oops, something went wrong.