update 优化 三方登录不同域名问题 采用新方案

This commit is contained in:
疯狂的狮子Li 2024-06-19 14:29:44 +08:00
parent fe1942c247
commit c206ab5b4a
4 changed files with 14 additions and 8 deletions

View File

@ -1,10 +1,14 @@
import request from '@/utils/request'; import request from '@/utils/request';
// 绑定账号 // 绑定账号
export function authBinding(source: string) { export function authBinding(source: string, tenantId: string) {
return request({ return request({
url: '/auth/binding/' + source, url: '/auth/binding/' + source,
method: 'get' method: 'get',
params: {
tenantId: tenantId,
domain: window.location.host
}
}); });
} }

View File

@ -17,8 +17,9 @@ const loading = ref(true);
const code = route.query.code as string; const code = route.query.code as string;
const state = route.query.state as string; const state = route.query.state as string;
const source = route.query.source as string; const source = route.query.source as string;
const tenantId = route.query.tenantId as string ? route.query.tenantId as string : '000000'; const stateJson = JSON.parse(atob(state));
const domain = route.query.domain as string; const tenantId = stateJson.tenantId as string ? stateJson.tenantId as string : '000000';
const domain = stateJson.domain as string;
const processResponse = async (res: any) => { const processResponse = async (res: any) => {
if (res.code !== 200) { if (res.code !== 200) {
@ -67,6 +68,7 @@ const init = async () => {
let urlFull = new URL(window.location.href); let urlFull = new URL(window.location.href);
urlFull.host = domain; urlFull.host = domain;
window.location.href = urlFull.toString(); window.location.href = urlFull.toString();
return;
} }
const data: LoginData = { const data: LoginData = {

View File

@ -191,10 +191,10 @@ const initTenantList = async () => {
* @param type * @param type
*/ */
const doSocialLogin = (type: string) => { const doSocialLogin = (type: string) => {
authBinding(type).then((res: any) => { authBinding(type, loginForm.value.tenantId).then((res: any) => {
if (res.code === HttpStatus.SUCCESS) { if (res.code === HttpStatus.SUCCESS) {
// //
window.location.href = res.data + '&tenantId=' + loginForm.value.tenantId + '&domain=' + window.location.host; window.location.href = res.data;
} else { } else {
ElMessage.error(res.msg); ElMessage.error(res.msg);
} }

View File

@ -84,9 +84,9 @@ const unlockAuth = (row: any) => {
}; };
const authUrl = (source: string) => { const authUrl = (source: string) => {
authBinding(source).then((res: any) => { authBinding(source, useUserStore().tenantId).then((res: any) => {
if (res.code === 200) { if (res.code === 200) {
window.location.href = res.data + '&tenantId=' + useUserStore().tenantId + '&domain=' + window.location.host; window.location.href = res.data;
} else { } else {
proxy?.$modal.msgError(res.msg); proxy?.$modal.msgError(res.msg);
} }