Browse Source

refactor(nc-gui): use single api instance in auth middleware

pull/3801/head
braks 2 years ago
parent
commit
0d46625cc4
  1. 14
      packages/nc-gui/middleware/auth.global.ts

14
packages/nc-gui/middleware/auth.global.ts

@ -1,6 +1,6 @@
import { message } from 'ant-design-vue' import type { Api } from 'nocodb-sdk'
import { defineNuxtRouteMiddleware, navigateTo } from '#app' import type { Actions } from '~/composables'
import { useApi, useGlobal, useRoles } from '#imports' import { defineNuxtRouteMiddleware, message, navigateTo, useApi, useGlobal, useRoles } from '#imports'
/** /**
* Global auth middleware * Global auth middleware
@ -37,7 +37,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
const { allRoles } = useRoles() const { allRoles } = useRoles()
/** if user isn't signed in and google auth is enabled, try to check if sign-in data is present */ /** if user isn't signed in and google auth is enabled, try to check if sign-in data is present */
if (!state.signedIn && state.appInfo.value.googleAuthEnabled) await tryGoogleAuth() if (!state.signedIn && state.appInfo.value.googleAuthEnabled) await tryGoogleAuth(api, state.signIn)
/** if public allow all visitors */ /** if public allow all visitors */
if (to.meta.public) return if (to.meta.public) return
@ -86,11 +86,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
/** /**
* If present, try using google auth data to sign user in before navigating to the next page * If present, try using google auth data to sign user in before navigating to the next page
*/ */
async function tryGoogleAuth() { async function tryGoogleAuth(api: Api<any>, signIn: Actions['signIn']) {
const { signIn } = useGlobal()
const { api } = useApi()
if (window.location.search && /\bscope=|\bstate=/.test(window.location.search) && /\bcode=/.test(window.location.search)) { if (window.location.search && /\bscope=|\bstate=/.test(window.location.search) && /\bcode=/.test(window.location.search)) {
try { try {
const { const {

Loading…
Cancel
Save