feat(login): 更新登录流程以支持SSO认证

- 修改.env文件指向新的后端本地环境地址
- 在登录表单中引入ssoCallBack和verifyOld接口
- 实现登录成功后的token存储逻辑
- 调整登录验证逻辑,优先使用新SSO验证接口
- 添加SSO回调处理函数,用于获取并存储认证信息
master
钟良源 3 months ago
parent 17361c3285
commit a3909bfca0

@ -11,4 +11,7 @@ NEXT_PUBLIC_DEV_CODE_SERVER_HOST='http://192.168.5.119:8443'
#NEXT_PUBLIC_DEV_SERVER_HOST='http://192.168.5.129:80'
# 开发环境-119
NEXT_PUBLIC_DEV_SERVER_HOST='http://192.168.5.119:80'
#NEXT_PUBLIC_DEV_SERVER_HOST='http://192.168.5.119:80'
# 后端本地环境
NEXT_PUBLIC_DEV_SERVER_HOST='http://192.168.5.158:8103'

@ -33,7 +33,7 @@ export const ssoLogin = ({ username, password }: Record<string, any>) => {
});
};
export const verify = ({ username, password }): Promise<LoginRes> => {
export const verifyOld = ({ username, password }): Promise<LoginRes> => {
return fetch('/api/user-center/verify', {
method: 'POST',
headers: {
@ -48,4 +48,34 @@ export const verify = ({ username, password }): Promise<LoginRes> => {
}
return data;
});
};
export const verify = ({ username, password }): Promise<LoginRes> => {
return fetch('/api/sso/verify', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ username, password: password })
}).then(async (res) => {
const data = await res.json();
return data;
});
};
export const ssoCallBack = ({ ticket, redirectUrl }) => {
const params = new URLSearchParams({ ticket, redirectUrl });
return fetch(`/api/sso/callback?${params.toString()}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
}).then(async (res) => {
const data = await res.json();
if (data && res.status === 200) {
localStorage.setItem('userStatus', 'login');
}
return data;
});
};

@ -9,11 +9,12 @@ import {
import { FormInstance } from '@arco-design/web-react/es/Form';
import { IconLock, IconUser } from '@arco-design/web-react/icon';
import React, { useEffect, useRef, useState } from 'react';
import { ssoLogin, verify } from '@/api/sso';
import { ssoCallBack, ssoLogin, verify, verifyOld } from '@/api/sso';
import useStorage from '@/utils/useStorage';
import useLocale from '@/utils/useLocale';
import locale from './locale';
import styles from './style/index.module.less';
import { setToken } from '@/utils/auth';
export default function LoginForm() {
const formRef = useRef<FormInstance>();
@ -36,8 +37,10 @@ export default function LoginForm() {
}
// 记录登录状态
localStorage.setItem('userStatus', 'login');
// 保存Token
setToken(token as string);
// 跳转首页
// window.location.href = '/dashboard/workplace';
window.location.href = '/dashboard/workplace';
}
async function loginRequest(params) {
@ -46,8 +49,13 @@ export default function LoginForm() {
try {
const res = await verify(params as any);
if (res.code === 200) {
await ssoLogin(params);
afterLoginSuccess(params);
if (res.data.code === 200) {
const tokenData = await ssoCallBack(res.data);
afterLoginSuccess(params, tokenData.data);
}
else {
setErrorMessage(res.msg);
}
}
else {
setErrorMessage(res.msg);

Loading…
Cancel
Save