feat: Added login page

This commit is contained in:
Xeovalyte 2023-06-04 22:47:48 +02:00
parent f360dcec8c
commit 08a24cae07
9 changed files with 74 additions and 7 deletions

6
webv2/app.config.ts Normal file
View File

@ -0,0 +1,6 @@
export default defineAppConfig({
ui: {
primary: 'cyan',
gray: 'cool'
}
})

View File

@ -1,9 +1,5 @@
<template>
<div>
<a :href="config.public.oauthUrl">Discord</a>
<div class="min-h-screen w-full overflow-y-auto bg-gray-100 dark:bg-gray-900">
<NuxtLayout />
</div>
</template>
<script setup>
const config = useRuntimeConfig()
</script>

3
webv2/layouts/blank.vue Normal file
View File

@ -0,0 +1,3 @@
<template>
<NuxtPage />
</template>

View File

@ -0,0 +1,5 @@
<template>
<div>
<NuxtPage />
</div>
</template>

25
webv2/middleware/auth.js Normal file
View File

@ -0,0 +1,25 @@
export default defineNuxtRouteMiddleware(async (to) => {
if (process.server) {
return
}
try {
const user = await $fetch('/api/auth/user')
if (!user.id) {
throw createError({ statusCode: 500, statusMessage: 'No user was found' })
}
useState('user', () => user)
if (to.meta.moderator && !user.role.moderator) {
return navigateTo('/')
}
} catch (e) {
console.error('Failed to get user', e)
useState('user', () => null)
return navigateTo('/login')
}
})

View File

@ -1,5 +1,6 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
ssr: false,
typescript: {
typeCheck: true
},

View File

@ -7,7 +7,8 @@
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"lint": "eslint ."
"lint": "eslint .",
"lint-fix": "eslint . --fix"
},
"devDependencies": {
"@nuxthq/ui": "^2.2.1",

13
webv2/pages/index.vue Normal file
View File

@ -0,0 +1,13 @@
<template>
<div>
Index
</div>
</template>
<script lang="ts" setup>
definePageMeta({
middleware: ['auth']
})
const user = useState('user')
</script>

17
webv2/pages/login.vue Normal file
View File

@ -0,0 +1,17 @@
<template>
<div class="flex h-screen flex-col items-center justify-center">
<h1 class="text-primary-500 mb-5 text-center text-3xl font-bold">Polarcraft S5</h1>
<p class="mx-3 mb-5 max-w-2xl">
<b>Welkom bij Polarcraft seizoen 5!</b> Start door in te loggen met Discord en vervolgens je account te koppelen met Minecraft. Als je problemen hebt maak dan in Discord een post aan in het <b>#help</b> channel.
</p>
<UButton @click="navigateTo(config.public.oauthUrl, { external: true })">Log in with Discord</UButton>
</div>
</template>
<script lang="ts" setup>
definePageMeta({
layout: 'blank'
})
const config = useRuntimeConfig()
</script>