From 0fc56326dff522771dbc6e79d428ad2b87cdf310 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Fri, 19 Aug 2022 15:56:21 +0200 Subject: [PATCH 01/11] feat(gui-v2): add google auth signup option --- packages/nc-gui-v2/middleware/auth.global.ts | 32 +++++++++++++++++-- packages/nc-gui-v2/package-lock.json | 19 +++++++++++ packages/nc-gui-v2/package.json | 1 + packages/nc-gui-v2/pages/signup/[[token]].vue | 14 ++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui-v2/middleware/auth.global.ts b/packages/nc-gui-v2/middleware/auth.global.ts index 8c85c53571..3c88944342 100644 --- a/packages/nc-gui-v2/middleware/auth.global.ts +++ b/packages/nc-gui-v2/middleware/auth.global.ts @@ -1,5 +1,6 @@ +import { message } from 'ant-design-vue' import { defineNuxtRouteMiddleware, navigateTo } from '#app' -import { useGlobal } from '#imports' +import { useApi, useGlobal } from '#imports' /** * Global auth middleware @@ -20,9 +21,11 @@ import { useGlobal } from '#imports' * }) * ``` */ -export default defineNuxtRouteMiddleware((to, from) => { +export default defineNuxtRouteMiddleware(async (to, from) => { const state = useGlobal() + await tryGoogleAuth() + /** if public allow */ if (to.meta.public) return @@ -48,3 +51,28 @@ export default defineNuxtRouteMiddleware((to, from) => { } } }) + +async function tryGoogleAuth() { + const { signIn } = useGlobal() + + const { api } = useApi() + + if (window.location.search && /\bscope=|\bstate=/.test(window.location.search) && /\bcode=/.test(window.location.search)) { + try { + const { + data: { token }, + } = await api.instance.post( + `/auth/${window.location.search.includes('state=github') ? 'github' : 'google'}/genTokenByCode${window.location.search}`, + ) + + signIn(token) + } catch (e: any) { + if (e.response && e.response.data && e.response.data.msg) { + message.error({ content: e.response.data.msg }) + } + } + + const newURL = window.location.href.split('?')[0] + window.history.pushState('object', document.title, newURL) + } +} diff --git a/packages/nc-gui-v2/package-lock.json b/packages/nc-gui-v2/package-lock.json index f30469a424..93cc11aef9 100644 --- a/packages/nc-gui-v2/package-lock.json +++ b/packages/nc-gui-v2/package-lock.json @@ -36,6 +36,7 @@ "@iconify-json/clarity": "^1.1.4", "@iconify-json/eva": "^1.1.2", "@iconify-json/ic": "^1.1.7", + "@iconify-json/logos": "^1.1.14", "@iconify-json/lucide": "^1.1.36", "@iconify-json/material-symbols": "^1.1.8", "@iconify-json/mdi": "^1.1.25", @@ -1041,6 +1042,15 @@ "@iconify/types": "*" } }, + "node_modules/@iconify-json/logos": { + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/@iconify-json/logos/-/logos-1.1.14.tgz", + "integrity": "sha512-SvSxKubQbP/7Wdb3loShUeRGv82ejkNo5gjzvJzQeauntuU4aZjDrx0mnkhFZgNYd3li/mxvzPn79Xc5SGVliw==", + "dev": true, + "dependencies": { + "@iconify/types": "*" + } + }, "node_modules/@iconify-json/lucide": { "version": "1.1.38", "resolved": "https://registry.npmjs.org/@iconify-json/lucide/-/lucide-1.1.38.tgz", @@ -15853,6 +15863,15 @@ "@iconify/types": "*" } }, + "@iconify-json/logos": { + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/@iconify-json/logos/-/logos-1.1.14.tgz", + "integrity": "sha512-SvSxKubQbP/7Wdb3loShUeRGv82ejkNo5gjzvJzQeauntuU4aZjDrx0mnkhFZgNYd3li/mxvzPn79Xc5SGVliw==", + "dev": true, + "requires": { + "@iconify/types": "*" + } + }, "@iconify-json/lucide": { "version": "1.1.38", "resolved": "https://registry.npmjs.org/@iconify-json/lucide/-/lucide-1.1.38.tgz", diff --git a/packages/nc-gui-v2/package.json b/packages/nc-gui-v2/package.json index 29fbe47465..cf1b4f1729 100644 --- a/packages/nc-gui-v2/package.json +++ b/packages/nc-gui-v2/package.json @@ -42,6 +42,7 @@ "@iconify-json/clarity": "^1.1.4", "@iconify-json/eva": "^1.1.2", "@iconify-json/ic": "^1.1.7", + "@iconify-json/logos": "^1.1.14", "@iconify-json/lucide": "^1.1.36", "@iconify-json/material-symbols": "^1.1.8", "@iconify-json/mdi": "^1.1.25", diff --git a/packages/nc-gui-v2/pages/signup/[[token]].vue b/packages/nc-gui-v2/pages/signup/[[token]].vue index da97ee9eb7..947b33983b 100644 --- a/packages/nc-gui-v2/pages/signup/[[token]].vue +++ b/packages/nc-gui-v2/pages/signup/[[token]].vue @@ -96,6 +96,8 @@ async function signUp() { }) } +function googleSignUp() {} + function resetError() { if (error) error = null } @@ -152,6 +154,18 @@ function resetError() { + + + + + Sign up with Google + + +
Date: Fri, 19 Aug 2022 16:05:27 +0200 Subject: [PATCH 02/11] chore(gui-v2): check if signed in before trying google auth --- packages/nc-gui-v2/middleware/auth.global.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/nc-gui-v2/middleware/auth.global.ts b/packages/nc-gui-v2/middleware/auth.global.ts index 3c88944342..d670c48bc6 100644 --- a/packages/nc-gui-v2/middleware/auth.global.ts +++ b/packages/nc-gui-v2/middleware/auth.global.ts @@ -24,16 +24,15 @@ import { useApi, useGlobal } from '#imports' export default defineNuxtRouteMiddleware(async (to, from) => { const state = useGlobal() - await tryGoogleAuth() + /** 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 public allow */ + /** if public allow all visitors */ if (to.meta.public) return - /** if shred base allow without validating */ + /** if shared base allow without validating */ if (to.params?.projectType === 'base') return - if (to.meta.public) return - /** if auth is required or unspecified (same as required) and user is not signed in, redirect to signin page */ if ((to.meta.requiresAuth || typeof to.meta.requiresAuth === 'undefined') && !state.signedIn.value) { return navigateTo('/signin') From b87118a917d7915ab83d8cf319da28a45334b3f7 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Fri, 19 Aug 2022 17:09:59 +0200 Subject: [PATCH 03/11] chore(gui-v2): style fix --- packages/nc-gui-v2/components/general/SocialCard.vue | 2 +- packages/nc-gui-v2/components/general/Sponsors.vue | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/nc-gui-v2/components/general/SocialCard.vue b/packages/nc-gui-v2/components/general/SocialCard.vue index 6ca98e0114..548619618b 100644 --- a/packages/nc-gui-v2/components/general/SocialCard.vue +++ b/packages/nc-gui-v2/components/general/SocialCard.vue @@ -7,7 +7,7 @@ const isRtlLang = $computed(() => ['fa'].includes(currentLang.value))