Browse Source

feat(gui-v2): add google auth signup option

pull/3252/head
braks 2 years ago
parent
commit
0fc56326df
  1. 32
      packages/nc-gui-v2/middleware/auth.global.ts
  2. 19
      packages/nc-gui-v2/package-lock.json
  3. 1
      packages/nc-gui-v2/package.json
  4. 14
      packages/nc-gui-v2/pages/signup/[[token]].vue

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

@ -1,5 +1,6 @@
import { message } from 'ant-design-vue'
import { defineNuxtRouteMiddleware, navigateTo } from '#app' import { defineNuxtRouteMiddleware, navigateTo } from '#app'
import { useGlobal } from '#imports' import { useApi, useGlobal } from '#imports'
/** /**
* Global auth middleware * 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() const state = useGlobal()
await tryGoogleAuth()
/** if public allow */ /** if public allow */
if (to.meta.public) return 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)
}
}

19
packages/nc-gui-v2/package-lock.json generated

@ -36,6 +36,7 @@
"@iconify-json/clarity": "^1.1.4", "@iconify-json/clarity": "^1.1.4",
"@iconify-json/eva": "^1.1.2", "@iconify-json/eva": "^1.1.2",
"@iconify-json/ic": "^1.1.7", "@iconify-json/ic": "^1.1.7",
"@iconify-json/logos": "^1.1.14",
"@iconify-json/lucide": "^1.1.36", "@iconify-json/lucide": "^1.1.36",
"@iconify-json/material-symbols": "^1.1.8", "@iconify-json/material-symbols": "^1.1.8",
"@iconify-json/mdi": "^1.1.25", "@iconify-json/mdi": "^1.1.25",
@ -1041,6 +1042,15 @@
"@iconify/types": "*" "@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": { "node_modules/@iconify-json/lucide": {
"version": "1.1.38", "version": "1.1.38",
"resolved": "https://registry.npmjs.org/@iconify-json/lucide/-/lucide-1.1.38.tgz", "resolved": "https://registry.npmjs.org/@iconify-json/lucide/-/lucide-1.1.38.tgz",
@ -15853,6 +15863,15 @@
"@iconify/types": "*" "@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": { "@iconify-json/lucide": {
"version": "1.1.38", "version": "1.1.38",
"resolved": "https://registry.npmjs.org/@iconify-json/lucide/-/lucide-1.1.38.tgz", "resolved": "https://registry.npmjs.org/@iconify-json/lucide/-/lucide-1.1.38.tgz",

1
packages/nc-gui-v2/package.json

@ -42,6 +42,7 @@
"@iconify-json/clarity": "^1.1.4", "@iconify-json/clarity": "^1.1.4",
"@iconify-json/eva": "^1.1.2", "@iconify-json/eva": "^1.1.2",
"@iconify-json/ic": "^1.1.7", "@iconify-json/ic": "^1.1.7",
"@iconify-json/logos": "^1.1.14",
"@iconify-json/lucide": "^1.1.36", "@iconify-json/lucide": "^1.1.36",
"@iconify-json/material-symbols": "^1.1.8", "@iconify-json/material-symbols": "^1.1.8",
"@iconify-json/mdi": "^1.1.25", "@iconify-json/mdi": "^1.1.25",

14
packages/nc-gui-v2/pages/signup/[[token]].vue

@ -96,6 +96,8 @@ async function signUp() {
}) })
} }
function googleSignUp() {}
function resetError() { function resetError() {
if (error) error = null if (error) error = null
} }
@ -152,6 +154,18 @@ function resetError() {
</span> </span>
</button> </button>
<a
v-if="appInfo.googleAuthEnabled"
href="http://localhost:8080/auth/google"
class="submit after:(!bg-white) !text-primary border-1 border-primary"
>
<span class="flex items-center gap-2">
<LogosGoogleGmail />
Sign up with Google
</span>
</a>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<a-switch <a-switch
v-model:checked="subscribe" v-model:checked="subscribe"

Loading…
Cancel
Save