From 365069f7119f41e01f83ea038d738744e8cd49e4 Mon Sep 17 00:00:00 2001 From: npmrun <1549469775@qq.com> Date: Mon, 1 Jun 2026 15:09:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20Gitea=20OAuth=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=EF=BC=8C=E6=9B=B4=E6=96=B0=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E5=92=8C=E7=99=BB=E5=BD=95=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 3 ++ app/pages/auth/login.vue | 67 ++++++++++++++---------- server/api/auth/oauth/[provider]/callback.get.ts | 4 +- server/service/oauth/oauth-manager.ts | 28 ++++++++++ 4 files changed, 73 insertions(+), 29 deletions(-) diff --git a/.env.example b/.env.example index 873ff68..5a95d73 100644 --- a/.env.example +++ b/.env.example @@ -8,4 +8,7 @@ BOOTSTRAP_ADMIN_USERNAME=admin BOOTSTRAP_ADMIN_PASSWORD=123456qaz GITHUB_CLIENT_ID=your_github_client_id GITHUB_CLIENT_SECRET=your_github_client_secret +GITEA_CLIENT_ID=your_gitea_client_id +GITEA_CLIENT_SECRET=your_gitea_client_secret +GITEA_URL=https://gitea.com APP_URL=http://localhost:3399 \ No newline at end of file diff --git a/app/pages/auth/login.vue b/app/pages/auth/login.vue index dec62ae..a9d2f50 100644 --- a/app/pages/auth/login.vue +++ b/app/pages/auth/login.vue @@ -7,21 +7,6 @@ const route = useRoute() const { $toast } = useNuxtApp() const redirect = computed(() => route.query.redirect as string || '/') -onMounted(() => { - const url = new URL(window.location.href) - if (url.searchParams.get('oauth_success') === '1') { - refresh(true) - router.push('/') - } - if (url.searchParams.get('oauth_error')) { - const error = url.searchParams.get('oauth_error') - console.error('OAuth error:', error) - url.searchParams.delete('oauth_error') - window.history.replaceState({}, document.title, url.href); - $toast.error(`OAuth 登录失败: ${error}`) - } -}) - const loginForm = reactive({ username: '', password: '', @@ -43,6 +28,10 @@ async function loginWithGithub() { window.location.href = '/api/auth/oauth/github/authorize'; } +async function loginWithGitea() { + window.location.href = '/api/auth/oauth/gitea/authorize'; +} + async function fetchCaptcha() { captcha.loading = true try { @@ -82,6 +71,7 @@ async function handleLogin() { onMounted(() => { fetchCaptcha() + const url = new URL(window.location.href) if (url.searchParams.get('oauth_success') === '1') { refresh(true) @@ -90,6 +80,9 @@ onMounted(() => { if (url.searchParams.get('oauth_error')) { const error = url.searchParams.get('oauth_error') console.error('OAuth error:', error) + url.searchParams.delete('oauth_error') + window.history.replaceState({}, document.title, url.href) + $toast.error(`OAuth 登录失败: ${error}`) } }) @@ -155,12 +148,22 @@ onMounted(() => { - +
+ + + +