Browse Source

feat(gui-v2): add auth middleware

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
pull/2716/head
Braks 2 years ago committed by Pranav C
parent
commit
2b8ba168a9
  1. 15
      packages/nc-gui-v2/middleware/auth.global.ts
  2. 6
      packages/nc-gui-v2/pages/signin.vue
  3. 6
      packages/nc-gui-v2/pages/signup.vue

15
packages/nc-gui-v2/middleware/auth.global.ts

@ -0,0 +1,15 @@
import { defineNuxtRouteMiddleware, navigateTo, useNuxtApp } from '#app'
export default defineNuxtRouteMiddleware((to, from) => {
const { $state } = useNuxtApp()
/**
* By default, we assume that auth is required
* If not required, mark the page as `requiresAuth: false` using `definePageMeta`
*/
if ((to.meta.requiresAuth || typeof to.meta.requiresAuth === 'undefined') && !$state.signedIn.value) {
return navigateTo('/signin')
} else if (to.meta.requiresAuth === false && $state.signedIn.value) {
return navigateTo(from.path)
}
})

6
packages/nc-gui-v2/pages/signin.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { useHead } from '#imports' import { definePageMeta, useHead } from '#imports'
import { extractSdkResponseErrorMsg } from '~/utils/errorUtils' import { extractSdkResponseErrorMsg } from '~/utils/errorUtils'
import { navigateTo, useNuxtApp } from '#app' import { navigateTo, useNuxtApp } from '#app'
import { isEmail } from '~/utils/validation' import { isEmail } from '~/utils/validation'
@ -11,6 +11,10 @@ const { $api, $state } = $(useNuxtApp())
const { t } = useI18n() const { t } = useI18n()
definePageMeta({
requiresAuth: false,
})
useHead({ useHead({
title: t('title.headLogin'), title: t('title.headLogin'),
meta: [ meta: [

6
packages/nc-gui-v2/pages/signup.vue

@ -4,11 +4,17 @@ import { navigateTo } from '#app'
const { $api, $state } = useNuxtApp() const { $api, $state } = useNuxtApp()
definePageMeta({
requiresAuth: false,
})
const error = ref() const error = ref()
const form = reactive({ const form = reactive({
email: '', email: '',
password: '', password: '',
}) })
const signUp = async () => { const signUp = async () => {
error.value = null error.value = null
try { try {

Loading…
Cancel
Save