diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/Authentication/AuthService.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/Authentication/AuthService.cs index 60c8fc75..ecdbf68c 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/Authentication/AuthService.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/Authentication/AuthService.cs @@ -40,7 +40,7 @@ namespace Yi.Framework.Rbac.Application.Services.Authentication /// /// [HttpGet("auth/oauth/login/{scheme}")] - public async Task AuthOauthLoginAsync([FromRoute] string scheme, [FromQuery] string code) + public async Task AuthOauthLoginAsync([FromRoute] string scheme, [FromQuery] string code) { (var openId, var _) = await GetOpenIdAndNameAsync(scheme); var authEntity = await _repository.GetAsync(x => x.OpenId == openId && x.AuthType == scheme); @@ -50,7 +50,7 @@ namespace Yi.Framework.Rbac.Application.Services.Authentication throw new UserFriendlyException("第三方登录失败,请先注册后,在个人中心进行绑定该第三方后使用"); } var accessToken = await _accountManager.GetTokenByUserIdAsync(authEntity.UserId); - return accessToken; + return new { token= accessToken }; } /// diff --git a/Yi.Bbs.Vue3/src/hooks/useAuths.js b/Yi.Bbs.Vue3/src/hooks/useAuths.js index 8504448e..ae4d4c3f 100644 --- a/Yi.Bbs.Vue3/src/hooks/useAuths.js +++ b/Yi.Bbs.Vue3/src/hooks/useAuths.js @@ -164,5 +164,6 @@ export default function useAuths(opt) { logoutFun, clearStorage, registerFun, + loginSuccess, }; } diff --git a/Yi.Bbs.Vue3/src/views/Auth/index.vue b/Yi.Bbs.Vue3/src/views/Auth/index.vue index 82292cd6..808ea014 100644 --- a/Yi.Bbs.Vue3/src/views/Auth/index.vue +++ b/Yi.Bbs.Vue3/src/views/Auth/index.vue @@ -15,6 +15,11 @@ const type = ref(route.query.state); const message = ref(""); const scheme = ref(""); const authData = ref(""); +const closeWindow = () => { + setTimeout(() => { + window.close(); + }, 2000); +}; watch( () => code.value, async (val) => { @@ -31,19 +36,25 @@ watch( scheme.value = "QQ"; break; } - if (type.value === "0") { - const { data } = await authOtherLogin({ code: val }, scheme.value); - authData.value = data; - } else if (type.value === "1") { - const { data } = await authOtherBind({ code: val }, scheme.value); - authData.value = data; + try { + if (type.value === "0") { + const { data } = await authOtherLogin({ code: val }, scheme.value); + authData.value = data; + } else if (type.value === "1") { + const { data } = await authOtherBind({ code: val }, scheme.value); + authData.value = data; + } + } catch (error) { + if (error.status === 403) { + closeWindow(); + } } window.opener.postMessage({ authData: JSON.stringify(authData.value), type: scheme.value, }); - console.log(authData.value, "我是打开的窗口页"); message.value = "授权成功"; + closeWindow(); } }, { immediate: true } diff --git a/Yi.Bbs.Vue3/src/views/login/index.vue b/Yi.Bbs.Vue3/src/views/login/index.vue index 09197fe2..818e35f1 100644 --- a/Yi.Bbs.Vue3/src/views/login/index.vue +++ b/Yi.Bbs.Vue3/src/views/login/index.vue @@ -166,7 +166,7 @@ import useUserStore from "@/stores/user"; import useConfigStore from "@/stores/config"; const configStore = useConfigStore(); -const { loginFun, registerFun } = useAuths(); +const { loginFun, registerFun, loginSuccess } = useAuths(); const router = useRouter(); const route = useRoute(); const loginFormRef = ref(); @@ -318,6 +318,15 @@ const handleGiteeLogin = () => { "width=500,height=500,left=50,top=50" ); }; + +window.addEventListener("message", async (e) => { + const { authData, type } = e.data; + console.log(authData, "传到登录页的值"); + if (authData) { + await loginSuccess({ data: JSON.parse(authData) }); + window.close(); + } +});